sqlcmd.net validated sql reference
beginner ordering MySQL MariaDB SQL Server PostgreSQL SQLite

Sort Rows With ORDER BY

Control the order of result rows explicitly instead of relying on storage order.

Docker-validated Not currently validation-green

Sort rows from highest score to lowest

Without ORDER BY, a database can return rows in any convenient internal order.

Rows loaded before the example query runs.
Setup
CREATE TABLE scores (player VARCHAR(50), points INT);

INSERT INTO
  scores (player, points)
VALUES
  ('Ada', 42),
  ('Linus', 89),
  ('Grace', 65);
Shared across supported engines.
SQL
SELECT
  player,
  points
FROM
  scores
ORDER BY
  points DESC,
  player ASC;
Returned rows for the shared example.
playerpoints
Linus89
Grace65
Ada42

The result is only trustworthy because the query sets the row order explicitly.

Where this command helps.

  • showing the highest or lowest values first
  • making result sets deterministic for docs, tests, or exports

What the command is doing.

ORDER BY makes the output predictable and readable. In documentation and validation fixtures, explicit ordering keeps expected rows stable across engines.