DevPath · Learn to code ESPTEN

Introduction to SQL

Sort with ORDER BY

ORDER BY

ORDER BY sorts the result rows by one or more columns:

SELECT name, price FROM products ORDER BY price;       -- ascending (default)
SELECT name, price FROM products ORDER BY price DESC;  -- descending

It goes at the end of the query, after the WHERE if there is one:

SELECT * FROM products
WHERE price > 20
ORDER BY price DESC;
Put this into practice

DevPath is a hands-on course: you read the theory here; in the app you put it into practice with exercises that really run, offline.

Start free in the app →
← Filter rows with WHEREView the module →