> I now understand that it is an IDE related thing not something fundamental to the language.
No, is fundamental issue to the language!
The relational model is clear. You START with a relation and then compose with relational operators that return relations.
ie:
rel | project
Sql do it weird. Is like in OO, where instead of define a class THEN define the properties, you define the properties THEN define the class.
And this fundamental issue with the language goes deeper. The rules are ad-hoc for each sub-operator despite the fact using relational model MUST make it simply to compose.
So, you have rules for HAVING, GROUP BY, ORDER BY, WHERE, SELECT and so on and none are like the others, are different in small but annoy ways...
Having SELECT come first makes sense to me because it's the only part of the statement that's required. FROM and everything else is optional.
Also when reading a statement, you're mostly interested in what the returned fields are rather details like where they came from or how they're ordered. It kind of makes sense to put it at the start.
Maybe other syntax forms have their benefits, specially when writing, but I don't think SQL's choice is completely senseless either.
> SELECT come first makes sense to me because it's the only part of the statement that's required.
Only *IN SQL*.
You don't need it on the relational model, heck, no even in any other paradigm:
1
That is!. (aka: SELECT 1)
So this:
SELECT * FROM foo
is because SQL is made weird. More correctly, this should be only:
foo
Also, SELECT is not required all the time, you wanna do:
foo WHERE .id = 1
foo ORDER BY .id
foo ORDER BY .id WHERE .id = 1 //Note this is not valid in SQL, but because SQL is wrong!
But you probably think this as weird, because SQL in his peculiar implementation, that is, ok for one-off, ad-hoc query, and in THAT case, having the list of fields first is not that bad.
But now, when you see it this way, you note how MUCH nicer and simpler it could have been, because then each "fragment" of a SQL query could become *composable*.
But not on SQL, where the only "composition" is string concatenation, that is bad as you get.
SELECT itself should be optional. Languages with expressions are fairly intuitive, e.g. "int x = foo.bar;" where "foo.bar" is equivalent to the "SELECT bar FROM foo;" SQL statement. I don't breathe SQL every day, so I'm struggling to come up with a case where removing SELECT results in parsing ambiguity.
> I'm struggling to come up with a case where removing SELECT results in parsing ambiguity
It's actually useful to the person reading the code. It clearly defines where a statement starts, what it does and makes reading a query close to reading English. Show a SELECT FROM WHERE query to someone who does not know SQL and the person will understand it. It might be a bit harder if you remove the SELECT.
And this is another example of the ad-hoc problems of SQL: query terminators (;) are optional. If they weren't, there would be no abiguity where a statement would start: it's the first word after the previous terminator.
Having learned Prolog before SQL, it was weird when it clicked that both were relational languages, but SQL decided to hide that underneath a natural language facade and the inconsistencies that come with it.
Yeah. And SQL does it very weird because it mixes up the meaning of "selection". Selection doesn't mean what most people seem to think it means. In the relational algebra "select" is really what is happening in the "where" clause. Projection is the name for the thing that chooses the attributes ("columns") to put in the final result.
No, is fundamental issue to the language!
The relational model is clear. You START with a relation and then compose with relational operators that return relations.
ie:
Sql do it weird. Is like in OO, where instead of define a class THEN define the properties, you define the properties THEN define the class.And this fundamental issue with the language goes deeper. The rules are ad-hoc for each sub-operator despite the fact using relational model MUST make it simply to compose.
So, you have rules for HAVING, GROUP BY, ORDER BY, WHERE, SELECT and so on and none are like the others, are different in small but annoy ways...