Well, it is not that simple. It is a declarative language, but of course it has a logic, an algorithm. But not in that sense. For a simple query it might look alike, but in general there is a so called query optimizer task, that is calculating a query plan for that specific query. A query plan is taking into account indexes, set sizes and many other circumstances to get a specific execution order.
Look here for some theory:
http://infolab.stanford.edu/~hyunjung/cs346/ioannidis.pdf[
^]
But if you google for "query optimizes" you will find several interesting articles about different RDBMS, since this is key feature of everyone, thus different.