Skip to content
techsnow

Reading Data

ORDER BY and LIMIT

SELECT name, marks FROM students
ORDER BY marks DESC
LIMIT 3;

Output

name  | marks
------+------
Sara  | 92
Ali   | 85
Bilal | 78
  • ORDER BY sorts: ASC (default, smallest first) or DESC.
  • Sort by several columns: ORDER BY city, marks DESC.
  • LIMIT 10 OFFSET 20 skips 20 rows and takes the next 10, which is how pagination works.