4 ms·
No, it should come after WHERE, GROUP BY but before ORDER BY. From my favorite SQL tutorial[1]: The lexical ordering is: SELECT FROM WHERE GRO
by em500 3y ago
No, it should come after WHERE, GROUP BY but before ORDER BY. From my favorite SQL tutorial[1]:
The lexical ordering is:
SELECT
FROM
WHERE
GROUP BY
HAVING
UNION
ORDER BY
while the logical order is:
FROM
WHERE
GROUP BY
HAVING
SELECT
UNION
ORDER BY
[1] https://blog.jooq.org/10-easy-steps-to-a-complete-understanding-of-sql/ https://blog.jooq.org/10-easy-steps-to-a-complete-understand...
- nivertech 3y agoYour example for a row-oriented just adds UNION. But you need first to order by column to get the rows in the desired order, while SELECT just indicates which column from the rows to return. source table -> filtered rowset -> grouped rowset -> filtered grouped rowset -> ordered rows -> ordered rows with selected columns only Source: I was working several years as a Human Query Planner for the columnar DB ;)
- deleted 3y ago[deleted]