Sorting with ORDER BY · ORDER BYによるソート
Sorting the result
The rows come back in no particular order. Add ORDER BY to sort them by a column:
ASCsorts ascending (smallest first) — this is the default.DESCsorts descending (largest first).
結果の並べ替え
行は特定の順序で戻ってきません。列で並べ替えるには ORDER BY を追加します:
SELECT name, score FROM student ORDER BY score DESC;
ASCで昇順(小さい順)に並べ替えます — これがデフォルトです。DESCで降順(大きい順)に並べ替えます。
Sorting by more than one column
Sort text columns alphabetically:
You can sort by several columns: ORDER BY form ASC, score DESC sorts by form first, then by score within each form. ORDER BY always comes last in the query.
複数の列での並べ替え
テキスト列をアルファベット順に並べ替えます:
SELECT name FROM student ORDER BY name;
複数の列で並べ替えることができます:ORDER BY form ASC, score DESC はまずクラスで並べ替え、その後の各クラス内で得点で並べ替えます。ORDER BY は常にクエリの最後に置かれます。
Common mistakes
- The default sort is ascending; add
DESCfor descending. ORDER BYcomes near the end of the query.
よくあるミス
- デフォルトの並べ替えは昇順です。降順にする場合は
DESCを追加します。 ORDER BYはクエリの末尾付近に置きます。
ORDER BY sorts the rows · ORDER BYは行を並べ替える
ORDER BY puts the result rows in order, like a sort. · ORDER BYは結果行をソートのように順序付けする。
Show every student's name and score, highest score first. · 全生徒のnameとscoreを表示し、得点が高い順にする。
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。
Show every student's name, sorted alphabetically (A to Z). · 全生徒のnameを表示し、アルファベット順(A〜Z)で並べ替える。
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。