3 ms·
This was a historical decision because SQL is a declarative language. I was confused for too long, I want to admit, about the SQL order: FROM/JOIN → WHERE → G
by lackoftactics 1y ago
This was a historical decision because SQL is a declarative language.
I was confused for too long, I want to admit, about the SQL order:
FROM/JOIN → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT
As a self-taught developer, I didn't know what I was missing, but now the mechanics seem clear, and if somebody really needs to handle SELECT with given names, then he should probably use CTE:
WITH src AS (SELECT * FROM sales),
proj AS (SELECT customer_id, total_price AS total FROM src),
filt AS (SELECT * FROM proj WHERE total > 100)
SELECT * FROM filt;
- balfirevic 1y ago> This was a historical decision because SQL is a declarative language It would be equally declarative if FROM came first.
- deleted 1y ago[deleted]
- lackoftactics 1y agoYou are right to point this out, fair point
- 9rx 1y ago> This was a historical decision because SQL is a declarative language. What do you mean? Both ALPHA (the godfather declarative database language created by Codd himself) and QUEL, both of which inspired SQL, put "FROM" first. Fun fact: SQL was originally known as SEQUEL, which was intended to be a wordplay on being a followup to QUEL. Another commenter makes a good case that SQL ended up that way because it was trying to capture relational algebra notation (i.e. π₁(R), where π~select, ₁~column, R~table). Yet relational algebra is procedural, not declarative. Relational calculus is the declarative branch. Although the most likely explanation remains simply that SEQUEL, in addition to being fun wordplay, also stood for Structured English Query Language. In English, we're more likely to say "select the bottle from the fridge", rather than "from the fridge, select the bottle". Neither form precludes declarative use.