I am surprised that SQL Server hasn't offered Linq syntax as an option for writing queries and stored procedures; could always start such queries with `Using Linq:` prefix so the query engine knows it's not using T-SQL...
Shouldn't FROM come before SELECT in SQL? (2011)
31–40 of 137 posts
Re: Shouldn't FROM come before SELECT in SQL? (2011)
#32 SELECT FROM scarr
FIELDS carrid, carrname
ORDER BY carrid
INTO TABLE @DATA(result1).
and SELECT carrid, carrname
FROM scarr
ORDER BY carrid
INTO TABLE @DATA(result2).
https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/a...Re: Shouldn't FROM come before SELECT in SQL? (2011)
#33My 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.
Re: Shouldn't FROM come before SELECT in SQL? (2011)
#34Earlier quoted context omitted.
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)
#35"The syntax is meant to resemble English", obviously. The link to https://www.lib.umn.edu/collections/special?id=291 is dead, though?
What SQL shares with English (and most other natural languages) is that the rules are sometimes confusing/inconsistent/illogical, but evolution is very slow so most of us are probably stuck with the status quo during our lifetimes (career time for SQL) due to the overwhelming network effects.
A simple way to demonstrate this is how we ended up with cities that have massively different pronunciation even though the spelling is similar.
Re: Shouldn't FROM come before SELECT in SQL? (2011)
#36I would like coffee from Starbucks. I don't say, from Starbucks I would like coffee
In standard SQL syntax you’re essentially asking for what you want at your house then driving to a Starbucks.
More readable but doesn’t follow the execution order at all.
Re: Shouldn't FROM come before SELECT in SQL? (2011)
#37This is valid SQL.
SELECT 1;
The SQL commands are SELECT, UPDATE, INSERT, etc. Therefore, those commands should be the first thing in an instruction. If you have a file full of SQL, you probably want all the lines to start with those commands. Gonna be pretty weird to read if you have both SELECT and UPDATE lines that start with FROM. Probably difficult for the parser also. Even hairier when it comes to subqueries.I do however, strongly agree that the most common scenario for user workflow is to choose tables first, then choose columns from those tables. I don't know if changing the language is really the answer. Intelligent tooling can and does already solve this. What I typically do is start all my queries by selecting *, then I go back and fill in the columns last.
Re: Shouldn't FROM come before SELECT in SQL? (2011)
#38FROM is not a command, it's a parameter, and an optional one at that. This is valid SQL. SELECT 1; The SQL commands are SELECT, UPDATE, INSERT, etc. Therefore, those commands should be the first thing in an instruction. If you have a file full of SQL, you probably want all the lines to start with those commands. Gonna be pretty weird to read if you have both SELECT and UPDATE lines that start with FROM. Probably diff…
Re: Shouldn't FROM come before SELECT in SQL? (2011)
#39FROM is not a command, it's a parameter, and an optional one at that. This is valid SQL. SELECT 1; The SQL commands are SELECT, UPDATE, INSERT, etc. Therefore, those commands should be the first thing in an instruction. If you have a file full of SQL, you probably want all the lines to start with those commands. Gonna be pretty weird to read if you have both SELECT and UPDATE lines that start with FROM. Probably diff…
Newbies I help sometimes wonder why things they reference in the SELECT part aren't visible/available in the FROM clause and that's because one is selecting the result of FROM ... JOIN ... WHERE etc anyway
Re: Shouldn't FROM come before SELECT in SQL? (2011)
#40"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 contrast, the father of SQL, Alpha, allowed: "From the refrigerator, select the green apples, insert more milk, and remove any expired items."