1SELECT DISTINCT column, AGG_FUNC(column_or_expression), …
2FROM mytable
3 JOIN another_table
4 ON mytable.column = another_table.column
5 WHERE constraint_expression
6 GROUP BY column
7 HAVING constraint_expression
8 ORDER BY column ASC/DESC
9 LIMIT count OFFSET COUNT;
1SQL order of execution defines the
2execution order of clauses.
3
4-Select
5It starts execution with
6-from (Choose and join tables to get base data)
7after from
8-where ( filters base data )
9-group by (Aggregates base data)
10-having (filters aggregated data)
11-select (returns final data)
12-order by (sorts the final data)
13-limit (limits the returned data to a row count)
14
15Only select and from are mandatory