While debugging some code, I stumbled into an error pretty much like the following:
SELECT * FROM person WHERE family_size > 3 ORDER BY birthday AND registered=0;
The error is that the AND clause was intended to be in the WHERE clause. Ie:
WHERE family_size > 3 AND registered=0
The "flawed" query throws no SQL syntax error or warning. So I assume it's valid SQL. (right?)
But more interestingly, what is it supposed to do? I tested this is a couple of RDBMS and my best bet is that it's doing something like:
ORDER BY (birthday AND registered=0);
Am I right?
Is this intended SQL behavior? (such as expected resolution of operator precedence) Or is it some sort of fall-back?
Some details I should add after reading comments:
- The original query was for use in MySQL, but I'm mostly interested in the intended use of the SQL language.
- I did a quick test in MSAccess and behaved pretty much the same.
- The columns were originally integers, but for the MSAccess test I did, I used Date/Time for 'birthday', just because.