11. FROM
22. WHERE
33. GROUP BY
44. HAVING
55. SELECT
66. ORDER BY
7
8
9
10
11 The rows selected by a query are filtered first by the FROM clause join conditions, then the WHERE clause search conditions, and then the HAVING clause search conditions. Inner joins can be specified in either the FROM or WHERE clause without affecting the final result.
12
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
11. FROM (including joins)
22. WHERE
33. GROUP BY
44. HAVING
55. SELECT
66. ORDER BY
7