Example 1
Sort by priority, then by name
Rows with the same priority are then sorted alphabetically by name.
Source table data Rows loaded before the example query runs.
Setup
CREATE TABLE tasks (name VARCHAR(50), priority INT);
INSERT INTO
tasks (name, priority)
VALUES
('Deploy', 1),
('Backups', 2),
('Alerts', 1);Validated query Shared across supported engines.
SQL
SELECT
name,
priority
FROM
tasks
ORDER BY
priority ASC,
name ASC;Expected result Returned rows for the shared example.
| name | priority |
|---|---|
| Alerts | 1 |
| Deploy | 1 |
| Backups | 2 |
The secondary sort key makes the result deterministic across engines.