What do the numbers refer to in GROUP BY and ORDER BY clauses?


#1

Question

What do the numbers refer to in GROUP BY and ORDER BY clauses?

Answer

The numbers are a way to refer to the columns in the SELECT statement (ie. 1 is the first column selected, 2 is the second column selected, etc). For example, this:

SELECT col_A, col_B
FROM tbl
ORDER BY col_A;

is equivalent to:

SELECT col_A, col_B
FROM tbl
ORDER BY 1;