Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
SQL / POSTGRESQL / Learn / LESSON 10
ORDER BY controls result order. ASC is ascending and the default; DESC is descending. Add a tie-breaker such as id for deterministic ordering. Row order matters in this exercise.
Small example:
SELECT id, name FROM customers ORDER BY name ASC, id ASC;Working tables for this task. Grading also uses other datasets with the same schema.
| id | name | category | price | stock |
|---|---|---|---|---|
| 1 | Book Light | books | 12 | 8 |
| 2 | Bowl | home | 20 | 4 |
| 3 | Lamp | home | 30 | 2 |
| 4 | Notebook | books | 10 | 12 |
| 5 | Box | NULL | 5 | 0 |
| 6 | Book Ocean | books | 20 | 1 |
| 7 | Mug | home | 30 | 3 |
| 8 | Pen | books | 19.99 | 7 |
| 9 | Cable | tools | 20.01 | 5 |
| 10 | Clip | tools | 9.99 | 3 |
| 11 | Fan | home | 30.01 | 1 |
| 12 | Book Edge | books | 20.01 | 2 |
| id | name | city |
|---|---|---|
| 1 | Mira | Sofia |
| 2 | Niko | Varna |
| 3 | Iva | Sofia |
| 4 | Alex | NULL |
| 5 | Boris | Plovdiv |
| 6 | Lena | Burgas |
| id | customer_id | total |
|---|---|---|
| 1 | 1 | 20 |
| 2 | 1 | 30 |
| 3 | 2 | 10 |
| 4 | 3 | 0 |
| 5 | 6 | 40 |
Expected columns: id, name, price · row order is checked
Expected result (displayed data):
Loading…ORDER BY controls result order. ASC is ascending and the default; DESC is descending. Add a tie-breaker such as id for deterministic ordering. Row order matters in this exercise.
QUERY STANDBY
›