Live data from Hacker News

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

stackoverflow.com

1–10 of 137 posts

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

#3
Linq does this [0], maybe partially because it's SQL-like but built for working with enumerables instead so they could do what they wanted. One other quirk of SQL ordering that always gets me is that SET comes before WHERE in UPDATE. I always get terrified that I'll run without the WHERE or without selecting the WHERE. Thankfully a good database tool like DataGrip will yell at you if you try to do a modifying operation without a WHERE.

[0] https://learn.microsoft.com/en-us/dotnet/csharp/programming-...

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

#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`?

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

#9
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.

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

#10
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 ...;
Post reply on HN