strawquery PT
All lessons

Lesson 9 of 30

LIMIT and OFFSET

Today at the studio

The press team needs a "top three" for the newsletter and a "next four" for a sidebar. They do not want the whole table, only a slice. "Neat slices," says Nagi. "Like a good cake."

The idea

LIMIT n keeps only the first n rows of the result. Together with ORDER BY, it gives you a top list: sort first, then cut.

OFFSET k skips the first k rows before counting. LIMIT 4 OFFSET 3 means: skip three, then give me four. Without ORDER BY, a limit picks rows at random, so always sort first.

Example

SELECT title FROM episodes ORDER BY minutes DESC LIMIT 2 OFFSET 1

Your turn

0 of 4 questions

Question 1 of 4

The press kit wants the three most expensive merch items. Show product and price, most expensive first.

The order of the rows counts in this question.

Unofficial fan project. Titles belong to their creators and rights holders.