Hacker News new | ask | show | jobs
by nickpeterson 3703 days ago
MSSQL doesn't support it, but does support the ORDER BY 1,2 syntax that is very similar.

I don't believe GROUP BY n1,n2.. should be allowed, because it inverts the flow of control of the query. If you think about it, you're telling SQL to group by a column you haven't specified yet, using the order it appears in the SELECT clause. Someone could edit the query and add a new column at the front of the select list and completely change the meaning of the query. I think the ORDER BY clause has similar issues, but at least that occurs after the SELECT happens.

tl;dr I shouldn't have to look at the ordering of the select to understand what has been grouped by.

Order of SQL operations for the uninitiated, this explains why you can't, for instance, reference a column alias defined in a SELECT clause in the WHERE clause.

  6 SELECT
  1 FROM
  2 JOIN
  3 WHERE
  4 GROUP BY
  5 HAVING
  7 ORDER BY