Home › SQL Tutorial › SQL ORDER BY and LIMIT
SQL ORDER BY and LIMIT
Sort results and take the first few.
ORDER BY sorts ascending (ASC, the default) or descending (DESC). LIMIT n returns only n rows (MySQL, PostgreSQL, SQLite). SQL Server uses SELECT TOP n, and Oracle uses FETCH FIRST n ROWS ONLY.
Example code
SELECT name, country FROM Customers
ORDER BY country ASC, name DESC
LIMIT 3;