SQSQL · Lesson 3 of 8
ORDER BY, LIMIT & DISTINCT
Rows in a table have no guaranteed order. If you want the top 10 students by grade, you need to say so explicitly — that's ORDER BY and LIMIT.
DISTINCT removes duplicate rows from the result. Ask 'which ages appear in the table?' and you don't want 17 listed five times.
◆ Note
LIMIT/OFFSET is how apps implement pagination — page 3 with 20 items per page is LIMIT 20 OFFSET 40. Beware: without ORDER BY, pagination is meaningless, because the database is free to return rows in any order it likes.
LIMIT/OFFSET is how apps implement pagination — page 3 with 20 items per page is LIMIT 20 OFFSET 40. Beware: without ORDER BY, pagination is meaningless, because the database is free to return rows in any order it likes.