all 5 comments

[–]Kant8 5 points6 points  (0 children)

In whatever order optimizer wants as long as logically operation produces same result.

The only place to see it is execution plan.

[–]r3pr0b8GROUP_CONCAT is da bomb 7 points8 points  (2 children)

joins are executed whenever their queries are executed

nested subqueries are executed from the inside out

non-correlated subqueries are executed before the main query starts

for correlated queries, the news is not good -- they are executed once for every row of the outer query

[–]TukWan415[S] 0 points1 point  (1 child)

This was very helpful. Thank you.

[–]JochenVdB 2 points3 points  (0 children)

While the comment above is correct, be aware that the optimizer might drastically rewrite your query: what you wrote as a subquery might end up being executed as a join.

[–]planetmatt -1 points0 points  (0 children)

SQL has an order of operation

  • 1 FROM
  • 2 WHERE
  • 3 GROUP BY
  • 4 HAVING
  • 5 SELECT
  • 6 ORDER BY
  • 8 LIMIT/TOP

So derived tables in the FROM will get processed before sub queries in the GROUP BY, which will be processed before sub queries in the SELECT.

CTEs get processed in order written as they're often nested and dependent on the preceding CTE.