Live data from Hacker News

Shouldn't FROM come before SELECT in SQL? (2011)

stackoverflow.com

11–20 of 137 posts

Re: Shouldn't FROM come before SELECT in SQL? (2011)

#11
post #6

SELECT ... FROM ... is more natural for smaller SQL. When you get 1000 line SQL files or 100s of SQL files, code management pain makes you yearn for FROM ... SELECT ... (three cheers for data build tool!)

How about `table.attribute` entirely, instead of `SELECT attribute FROM table`?

You need some way to put an alias on tables so you can join a table more than once though I guess that can be optional, say

   SELECT table.attribute
or

   FROM table SELECT attribute
or

   FROM table as a,table as b WHERE a.x=b.y SELECT a.z

Re: Shouldn't FROM come before SELECT in SQL? (2011)

#13
If you ever need column name autocomplete, writing an UPDATE statement and changing it after is an ok workaround.

It would probably be a tough change to push through for the standard committee... a great one for users though, even if it takes 10+ years until you can use it in production.

Re: Shouldn't FROM come before SELECT in SQL? (2011)

#15
post #5

"The syntax is meant to resemble English", obviously. The link to https://www.lib.umn.edu/collections/special?id=291 is dead, though?

"Select green apples from the refrigerator" vs "from the refrigerator, select green apples" The first is much more naturally spoken.

In English. I think other languages would have different word orderings. German for one, and I think maybe Russian too.

Re: Shouldn't FROM come before SELECT in SQL? (2011)

#20

Also SELECT should be the last clause (at least for row-oriented DBMS, for columnar databases it might come before WHERE, GROUP BY, ORDER BY to hint which columns we want to select to query on). Row-oriented: FROM table_name WHERE condition GROUP BY ... HAVING ... ORDER BY ... SELECT column1, column2, ...; Columnar: FROM table_name SELECT column1, column2, ... ORDER BY ... WHERE condition GROUP BY ... HAVING ...;

Nah, in the row one, it should come before the order by.

Alternatively, its semantics could change to reflect this ordering, but it would loss expressiveness.

Post reply on HN