4 ms·
I have long wondered why we can write "ORDER BY 1" (meaning to order by the values in the first column), but it's illegal to say "GROUP BY 1". This article show
by CWuestefeld 7y ago
I have long wondered why we can write "ORDER BY 1" (meaning to order by the values in the first column), but it's illegal to say "GROUP BY 1". This article shows why that is.
- jvns 7y ago`group by 1` is actually allowed in several SQL implementations, and there's no reason it can't be -- the same as with column aliases the db engine can just rewrite select name, count(*) from table group by 1 as select name, count(*) from table group by name before executing the query
- erik_seaberg 7y agoI will never forget Percona telling us ORDER BY NULL would defeat something MySQL was getting wrong in a query that already wasn't ordered by anything. A coworker put it as "waving a dead chicken that doesn't even exist".