Posted at

If you write numbers in SQL | ORDER BY ...

Sorting is performed in the "x-th column".


Example

When sorting in the first column.

 mysql> SELECT * FROM examples ORDER BY 1 ASC; +------+-------+ | id | name | +------+-------+ | 1 | Carol | | 2 | Bob | | 3 | Alice | 

When sorting in the second column.

 mysql> SELECT * FROM examples ORDER BY 2 ASC; +------+-------+ | id | name | +------+-------+ | 3 | Alice | | 2 | Bob | | 1 | Carol | +------+-------+ 


environment

 Your MySQL connection id is 8 Server version: 5.7.12 Homebrew 


Original by

SQL | ORDER BY に数字を書くと...


About

About this translattion