3 ms·
The worst part about SQL is statement order. IIRC most SQL engines do FROM → WHERE → GROUP BY → HAVING → ORDER BY → SELECT → LIMIT → UNION, which is why you ca
by mFixman 7y ago
The worst part about SQL is statement order.
IIRC most SQL engines do FROM → WHERE → GROUP BY → HAVING → ORDER BY → SELECT → LIMIT → UNION, which is why you can SELECT after ORDER BY in the previous example but not after union.
If I were to start SQL from scratch I would allow statements in an arbitrary order and execute them in whichever order I coded them.
- tpetry 7y agoBut then i will not be SQL. SQL is built like this because all these operations are projections on a set. You can not really change their order and have meaningful results. Some oeprators can be swapped, but this part of the optimization process and nothing you need to be aware of.
- gigatexal 6y agothat hellscape doesn't exist and I am glad it doesn't. The order should just be considered a spec and accepted and worked around -- I think SQL has proven its staying power over the years.