SQL LIMIT / TOP

Return only the first rows.

✍️ 3 exercises + code challenge in this lesson

Limit the number of rows returned, which is useful for large tables and "top 5" lists.

  • MySQL, PostgreSQL and SQLite: LIMIT 5, with OFFSET 10 to skip rows (pagination).
  • SQL Server: SELECT TOP 5 ...
  • Oracle / standard SQL: FETCH FIRST 5 ROWS ONLY

Key Takeaways: SQL LIMIT / TOP

Mastering SQL LIMIT / TOP helps you write clean and reliable SQL code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

SQL LIMIT / TOP Code Example

SQL
-- The 3 most expensive products
SELECT ProductName, Price FROM Products
ORDER BY Price DESC
LIMIT 3;

-- Page 2 of customers, 4 per page
SELECT CustomerID, CustomerName FROM Customers
ORDER BY CustomerID
LIMIT 4 OFFSET 4;
Free sign-in required · Google login available

SQL LIMIT / TOP Practice Exercises

Check what you learned in “SQL LIMIT / TOP”.

/ 3 solved
Fill in the blank

Return only the first 5 rows (MySQL / SQLite).

SELECT * FROM Products  5;
✓ Correct! Not quite. Try again.
Multiple choice

Which keyword does SQL Server use instead of LIMIT?

✓ Correct! Not quite. Try again.
Code challenge

Select the 2 cheapest products (ProductName, Price).

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services