skip to today's puzzle

LIMIT keeps only the first few rows

LIMIT sets the maximum number of rows returned: LIMIT 3 stops after three rows, even if hundreds match. SQL results have no guaranteed order on their own, so pair LIMIT with ORDER BY — sort by the column you care about, then keep the top few. Dialect note: SQL Server writes this as SELECT TOP 3 instead of LIMIT, and Oracle uses FETCH FIRST 3 ROWS ONLY.

A tiny example

In plain English: Show me the three cafés with the highest ratings.

SELECT name, rating
FROM cafes
ORDER BY rating DESC
LIMIT 3;

Query result

namerating
Sunny Cup5
Corner Bean4.8
Morning Mug4.6

After sorting by rating, LIMIT kept just the top three.

Common questions

Why does LIMIT need ORDER BY for a top-N list?
Without ORDER BY the database may return any N rows it finds first. Add ORDER BY so 'top 5' really means the five highest or newest, then LIMIT 5 keeps just those.
Is LIMIT the same in every database?
PostgreSQL, MySQL and SQLite use LIMIT. SQL Server uses SELECT TOP 5 instead, and older Oracle uses FETCH FIRST 5 ROWS ONLY. The idea is identical; only the keyword changes.

Related SQL lessons

Practice LIMIT step by step

The Foundations Track has beginner puzzles built around this idea. Tap tiles, see real results. No terminal, no setup.

practice this in the course

Ready for a break?

A fresh, bite-sized SQL puzzle waits every morning. Tap tiles, see real results. No terminal, no setup, no timers.

Try today's free SQL puzzle