Live data from Hacker News

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

stackoverflow.com

131–137 of 137 posts

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

#131

Earlier quoted context omitted.

"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.

But SQL is using english words, what does german and russian have to do with it ?

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

#132

Earlier quoted context omitted.

I wonder if there is a concept of infinite length SQL tables. Not sure what would happen with: ORDER DESC COUNT(*) I can't find anything after a quick search except recursive views that must terminate (therefore aren't infinite)

COUNT is easy: > SELECT COUNT(*) FROM ℤ; ℵ₀ > SELECT COUNT(*) FROM ℝ; POWER(2,ℵ₀) > EXEC sp_configure 'continuum hypothesis','1'; > RECONFIGURE; > SELECT COUNT(*) FROM ℝ; ℵ₁ While non-termination is probably best left implementation-defined (to allow caller-terminated streams of infinite results where they make sense), ORDER BY would clearly be an error where no well-defined "first" or "next" result exists.

How fun it would be to receive a Cantor result in which as many elements from the original set as there were have been removed, leaving a set drawn from what you started with which still contains as many elements!

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

#133

My mental model was always that the order of keywords mirrored the order the database engine applied them. So WHERE is processed first and SELECT last.

It’s not really mirrored (assuming you meant reversed). Here’s a page describing the two orders in relation to each other from a wiki I wrote: https://github.com/weinberg/SQLToy/wiki/Two-Key-Concepts

Oh wow, the wiki / project looks fantastically interesting. I've bookmarked it for a deeper read in the future.

Yes I did mean reversed.

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

#134

Earlier quoted context omitted.

Alright, I start typing out "SELECT" in my super smart IDE, how does it know which table to suggest columns from?

Given that it is a very smart IDE, the column suggestion UI integrates table selection in a smart way. Once the IDE knows which table(s) you are referencing, it automatically fills in the FROM clause for you.

Looks like my IDE isn't that smart. So I will have to endure the unfriendliness of the SQL towards humans.

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

#135

Earlier quoted context omitted.

Given that it is a very smart IDE, the column suggestion UI integrates table selection in a smart way. Once the IDE knows which table(s) you are referencing, it automatically fills in the FROM clause for you.

Looks like my IDE isn't that smart. So I will have to endure the unfriendliness of the SQL towards humans.

Or just use a better language. SQL was designed for non-technical people, using statements that resemble the English they already know. It was not designed for tech-minded people who are able to grasp higher level technical concepts.

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

#136
Oh of course, that would be the single most needed fix for the language, enabling intellisense and aligning with real query execution order.

Look at Linq in C#, there they implemented it correctly and it's just awesome to use. It's so much more flexible and fun.

from ...

where ...

join ...

where ...

group ... by ...

where ...

select ...

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

#137
post #14

DuckDB does this. https://duckdb.org/2023/08/23/even-friendlier-sql.html#from-...

> This addresses one of the longest standing complaints about SQL, and the DuckDB team implemented it in 2 days. what a weird thing to say.

True, because with such decision the question is not whether it's possible to implement, but whether it's a good decision to do it.
Post reply on HN