LIMIT
clause format: Starts from
X
rows, Selects
Y
rows
-- LIMIT Y
-- LIMIT X Y
LIMIT
clause is used to limit the number of rows returned as a result
SELECT
id,
first_name
FROM students
LIMIT 2
LIMIT
clause for pagination.
If two arguments are passed to LIMIT clause, the first one
offset
, which indicates how many rows we want to skip.
In this example, we want to skip the first 10 records and get the following 5 records. In this case we want to get 3'th page
SELECT
first_name
last_name
FROM students
ORDER BY points DESC
LIMIT 10, 5
Selects the student with the highest points
SELECT *
FROM students
ORDER BY points DESC
LIMIT 1