LoginSignup
13
13

More than 1 year has passed since last update.

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

Last updated at Posted at 2016-05-03

「x番目のカラム」で並び替えがおこなわれる。

1番目のカラムで並び替える場合。

mysql> SELECT * FROM examples ORDER BY 1 ASC;

+------+-------+
| id   | name  |
+------+-------+
|    1 | Carol |
|    2 | Bob   |
|    3 | Alice |

2番目のカラムで並び替える場合。

mysql> SELECT * FROM examples ORDER BY 2 ASC;

+------+-------+
| id   | name  |
+------+-------+
|    3 | Alice |
|    2 | Bob   |
|    1 | Carol |
+------+-------+

環境

Your MySQL connection id is 8
Server version: 5.7.12 Homebrew

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

メンター受付

13
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
13