Limit the number of rows returned, which is useful for large tables and "top 5" lists.
- MySQL, PostgreSQL and SQLite:
LIMIT 5, withOFFSET 10to skip rows (pagination). - SQL Server:
SELECT TOP 5 ... - Oracle / standard SQL:
FETCH FIRST 5 ROWS ONLY
Return only the first rows.
✍️ 3 exercises + code challenge in this lessonLimit the number of rows returned, which is useful for large tables and "top 5" lists.
LIMIT 5, with OFFSET 10 to skip rows (pagination).SELECT TOP 5 ...FETCH FIRST 5 ROWS ONLYMastering 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.
-- 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;
Check what you learned in “SQL LIMIT / TOP”.
Return only the first 5 rows (MySQL / SQLite).
SELECT * FROM Products 5;
Which keyword does SQL Server use instead of LIMIT?
Select the 2 cheapest products (ProductName, Price).
Free sign-in required · Google login available
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