Skip to content
Quantoros

What does LIMIT do?

SQLLevel: FoundationFundamentals (Easy)

What does LIMIT do?

Hints
  • Define one output row and the source-table keys.
  • Check duplicates, NULLs and the order of filtering and aggregation.

Answer

LIMIT restricts the number of rows returned. Combined with OFFSET, it's used for pagination.

-- First 10 rows
SELECT * FROM products ORDER BY created_at DESC LIMIT 10;

-- Rows 11-20 (second page)
SELECT * FROM products ORDER BY created_at DESC LIMIT 10 OFFSET 10;

Note: LIMIT/OFFSET pagination gets slow on large offsets because the database still scans all the skipped rows. Cursor-based pagination (using a WHERE id > last_seen_id) is much more efficient for large datasets.

Source and licence: SQL Interview Questions — Arda Kocadoru · MIT

Related questions