Reputation: 163
What is the meaning of ORDER BY 1,2
Can we use numeric values in the ORDER BY
clause?
Is this a valid statement?
Upvotes: 1
Views: 1010
Reputation: 4377
ORDER BY 1, 2
will order your data by first and second expressions in your select. For example:
SELECT
Col1,
Col2
FROM
Table
ORDER BY
1
is the same as:
SELECT
Col1,
Col2
FROM
Table
ORDER BY
Col1
You can use this notation with expressions, for example:
SELECT
10 - IntCol1,
Col2
FROM
Table
ORDER BY
1
Upvotes: 3
Reputation: 3299
This is a valid statement. The numbers point to the column position in your result.
ORDER BY 1, 2
is the same as
ORDER BY MyTable.FirstColumn, MyTable.SecondColumn
Upvotes: 3
Reputation: 1967
Yes, it is. It is ordering by columns without specifying the column name. So ordering by 1,2 is ordering by the first column, then by the second column.
Check out this article for more info:
http://www.1keydata.com/sql/sqlorderby.html
Upvotes: 1