Stage 2 · Lesson 5 of 8
Limiting rows: LIMIT, TOP and OFFSET FETCH
Most queries in real apps return one page of results, not every row. and MySQL use with OFFSET (how many rows to skip). uses TOP (n), or the standard OFFSET ... ROWS FETCH NEXT ... ROWS ONLY form, which needs .
PostgreSQL also accepts the standard FETCH FIRST form. This is the first difference you will meet, where databases spell the same idea differently. Learn to recognise every form, even though you only write your own.
Always pair a limit with ORDER BY, or the rows you get are arbitrary. OFFSET works for early pages but gets slower as the number grows, because the database still reads the rows it skips. The performance stage shows a better method.
Common trapTOP or LIMIT without ORDER BY in a "latest ten" query.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking SQL for Tech Interviews
Design Gurus · Intermediate · Subscription
The basics, order of execution and functions chapters, each followed by graded problems
- CourseFreeSQLBolt
SQLBolt · Beginner
Free: Lessons 1 to 4, 8, 9 and 12 cover SELECT, filtering, sorting, NULLs, expressions and query order
Practise
Keep handy
Also worth your time
Walks through the logical order a query is evaluated in, which explains most early errors