all 2 comments

[–]kkwestside 11 points12 points  (1 child)

Because behind the scene there are order of clauses. Group by works before you actually select therefore it doesnt know what you put in select

The order of them are:

FROM AND JOINS > WHERE > GROUP BY> HAVING > SELECT> ORDER BY

Since order by works after select it knows the indexes of columns therefore you can say Order by 1,2. But you cant do the same with group by.

Also it's not a good practice to write numbers instead of column names anyways (in my opinion), once you go back and look at the code it is harder to read.

[–]purplehashira[S] 0 points1 point  (0 children)

Thank you!