SQL SELECT TOP, LIMIT, FETCH FIRST, ROWNUM – Complete Guide with Examples (2026-27)
The SQL SELECT TOP / LIMIT / FETCH FIRST / ROWNUM clause is used to limit the number of rows returned by a query. Instead of retrieving every row in a large table, these clauses let you return only the first N rows — making queries faster and more efficient. Different databases use different syntax for the same idea: SQL Server uses SELECT TOP, MySQL/PostgreSQL/SQLite use LIMIT, Oracle 12c+ uses FETCH FIRST n ROWS ONLY, and older Oracle uses ROWNUM. This guide covers all four with clear examples.
✅ What is SQL SELECT TOP / LIMIT?
When a table has thousands or millions of rows, retrieving all of them is slow and often unnecessary. The SELECT TOP / LIMIT / FETCH FIRST / ROWNUM clause solves this by telling the database: "Return only the first N rows, then stop."
✅ Useful for: previewing data, getting top 10 results, building paginated reports, improving query performance on large tables.
✅ Always use with ORDER BY — without ORDER BY, the "first N rows" are unpredictable because rows have no guaranteed order in SQL unless you specify one.
✅ Sample Employees Table (used in all examples):-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 1 | ANNI | IT | 10000 | Mumbai |
| 2 | POOJA | IT | 9000 | Pune |
| 3 | RAJ | SALES | 5000 | Delhi |
| 4 | SUJAN | HR | 8000 | Pune |
| 5 | MEENA | SALES | 12000 | Mumbai |
| 6 | PRAMOD | IT | 15000 | Bangalore |
| 7 | NILESH | HR | 7000 | Mumbai |
✅ SQL Syntax – All Databases
SQL Server SELECT TOP Syntax
SELECT TOP (number) column1, column2, ...
FROM table_name
WHERE condition
ORDER BY column_name;
MySQL PostgreSQL SELECT LIMIT Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition
ORDER BY column_name
LIMIT number;
Oracle 12c+ FETCH FIRST Syntax
SELECT column1, column2, ...
FROM table_name
ORDER BY column_name
FETCH FIRST number ROWS ONLY;
Oracle (older) ROWNUM Syntax
SELECT column1, column2, ...
FROM table_name
WHERE ROWNUM <= number;
✅ Database Comparison – Which Clause to Use
| Database | Clause to Use | Example |
|---|---|---|
| SQL Server / MS Access | SELECT TOP n | SELECT TOP 3 * FROM Employees; |
| MySQL / MariaDB | LIMIT n | SELECT * FROM Employees LIMIT 3; |
| PostgreSQL / SQLite | LIMIT n | SELECT * FROM Employees LIMIT 3; |
| Oracle 12c and later | FETCH FIRST n ROWS ONLY | SELECT * FROM Employees FETCH FIRST 3 ROWS ONLY; |
| Oracle (older versions) | WHERE ROWNUM <= n | SELECT * FROM Employees WHERE ROWNUM <= 3; |
| DB2 / Informix | FETCH FIRST n ROWS ONLY | SELECT * FROM Employees FETCH FIRST 3 ROWS ONLY; |
✅ Example 1 – SELECT TOP (SQL Server)
Return only the first 3 rows from the Employees table:
✅ SELECT Query (SQL Server):-
SELECT TOP (3) *
FROM Employees;
✅ Result Show:-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 1 | ANNI | IT | 10000 | Mumbai |
| 2 | POOJA | IT | 9000 | Pune |
| 3 | RAJ | SALES | 5000 | Delhi |
| 4 | SUJAN | HR | 8000 | Pune |
| 5 | MEENA | SALES | 12000 | Mumbai |
| 6 | PRAMOD | IT | 15000 | Bangalore |
| 7 | NILESH | HR | 7000 | Mumbai |
✅ Example 2 – SELECT LIMIT (MySQL / PostgreSQL)
Return only the first 3 rows using LIMIT:
✅ SELECT Query (MySQL / PostgreSQL):-
SELECT *
FROM Employees
LIMIT 3;
✅ Result Show:-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 1 | ANNI | IT | 10000 | Mumbai |
| 2 | POOJA | IT | 9000 | Pune |
| 3 | RAJ | SALES | 5000 | Delhi |
✅ Example 3 – TOP with ORDER BY (Top 3 Highest Salaries)
Get the 3 highest-paid employees — always combine TOP/LIMIT with ORDER BY for meaningful results:
✅ SELECT Query (SQL Server):-
SELECT TOP (3) *
FROM Employees
ORDER BY Salary DESC;
✅ SELECT Query (MySQL / PostgreSQL):-
SELECT *
FROM Employees
ORDER BY Salary DESC
LIMIT 3;
✅ Result Show:-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 6 | PRAMOD | IT | 15000 | Bangalore |
| 5 | MEENA | SALES | 12000 | Mumbai |
| 1 | ANNI | IT | 10000 | Mumbai |
ORDER BY Salary DESC to reliably get the 3 highest salaries.
✅ Example 4 – SELECT TOP PERCENT (SQL Server Only)
In SQL Server, you can use PERCENT to return a percentage of rows instead of a fixed number:
✅ SELECT Query (SQL Server only):-
-- Return the top 50% of rows (SQL Server only)
SELECT TOP (50) PERCENT *
FROM Employees
ORDER BY Salary DESC;
✅ Result Show (7 rows × 50% = 4 rows returned):-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 6 | PRAMOD | IT | 15000 | Bangalore |
| 5 | MEENA | SALES | 12000 | Mumbai |
| 1 | ANNI | IT | 10000 | Mumbai |
| 2 | POOJA | IT | 9000 | Pune |
✅ Example 5 – FETCH FIRST (Oracle 12c+ / DB2)
Oracle 12c and later supports the SQL standard FETCH FIRST syntax:
✅ SELECT Query (Oracle 12c+ / DB2):-
SELECT *
FROM Employees
ORDER BY Salary DESC
FETCH FIRST 3 ROWS ONLY;
✅ Result Show:-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 6 | PRAMOD | IT | 15000 | Bangalore |
| 5 | MEENA | SALES | 12000 | Mumbai |
| 1 | ANNI | IT | 10000 | Mumbai |
FETCH FIRST n ROWS ONLY is the ISO SQL standard syntax and is also supported in DB2, MariaDB 10.6+, and newer versions of PostgreSQL (as FETCH FIRST n ROWS ONLY after an OFFSET clause).
✅ Example 6 – ROWNUM (Older Oracle Versions)
In older Oracle databases (before 12c), use ROWNUM in a WHERE clause:
✅ SELECT Query (Oracle, older versions):-
SELECT *
FROM Employees
WHERE ROWNUM <= 3;
✅ Result Show:-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 1 | ANNI | IT | 10000 | Mumbai |
| 2 | POOJA | IT | 9000 | Pune |
| 3 | RAJ | SALES | 5000 | Delhi |
SELECT * FROM (SELECT * FROM Employees ORDER BY Salary DESC) WHERE ROWNUM <= 3;
✅ Example 7 – LIMIT with OFFSET (Pagination)
OFFSET tells SQL how many rows to skip before returning results. This is essential for pagination (showing page 1, page 2, page 3 etc.):
✅ SELECT Query (MySQL / PostgreSQL):-
-- Page 1: First 3 rows (rows 1-3)
SELECT * FROM Employees
ORDER BY ID
LIMIT 3 OFFSET 0;
-- Page 2: Next 3 rows (rows 4-6)
SELECT * FROM Employees
ORDER BY ID
LIMIT 3 OFFSET 3;
-- Page 3: Next 3 rows (rows 7-9)
SELECT * FROM Employees
ORDER BY ID
LIMIT 3 OFFSET 6;
✅ Result Show – Page 2 (LIMIT 3 OFFSET 3):-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 4 | SUJAN | HR | 8000 | Pune |
| 5 | MEENA | SALES | 12000 | Mumbai |
| 6 | PRAMOD | IT | 15000 | Bangalore |
✅ OFFSET in SQL Server (FETCH FIRST with OFFSET):-
-- Page 2 in SQL Server / Oracle 12c+
SELECT * FROM Employees
ORDER BY ID
OFFSET 3 ROWS
FETCH NEXT 3 ROWS ONLY;
OFFSET = (page_number - 1) × rows_per_pagePage 1: OFFSET 0 | Page 2: OFFSET 3 | Page 3: OFFSET 6 (for 3 rows per page)
✅ Key Points to Remember
✅ Always use ORDER BY — without ORDER BY, the rows returned are unpredictable. TOP/LIMIT without ORDER BY does not guarantee any particular rows.
✅ Syntax differs by database — TOP for SQL Server, LIMIT for MySQL/PostgreSQL, FETCH FIRST for Oracle 12c+, ROWNUM for older Oracle.
✅ TOP PERCENT is SQL Server only — MySQL and PostgreSQL do not have a PERCENT option.
✅ ROWNUM in Oracle applies before ORDER BY — always use a subquery when combining ROWNUM with ORDER BY in older Oracle.
✅ Use OFFSET for pagination — LIMIT with OFFSET (or OFFSET … FETCH NEXT in SQL Server) is the standard way to implement paged results.
✅ TOP/LIMIT improves performance — returning fewer rows reduces database memory usage and speeds up query execution on large tables.
✅ Common SQL TOP / LIMIT Mistakes to Avoid
Wrong:
SELECT TOP 3 * FROM Employees; — returns 3 arbitrary rows with no guaranteed order.Correct:
SELECT TOP 3 * FROM Employees ORDER BY Salary DESC; — returns the 3 highest-paid employees.
SQL Server does NOT support LIMIT. Using
LIMIT 3 in SQL Server will cause a syntax error. Use SELECT TOP (3) instead.
MySQL does NOT support TOP. Using
SELECT TOP 3 in MySQL will cause a syntax error. Use LIMIT 3 at the end of the query instead.
Wrong:
SELECT * FROM Employees WHERE ROWNUM <= 3 ORDER BY Salary DESC; — ROWNUM filters FIRST, then ORDER BY sorts the already-limited result.Correct: wrap in a subquery:
SELECT * FROM (SELECT * FROM Employees ORDER BY Salary DESC) WHERE ROWNUM <= 3;
To skip the first 5 rows: use
OFFSET 5 (not OFFSET 6). OFFSET 0 = no rows skipped (page 1). OFFSET 5 = skip first 5 rows (page 2 when using 5 rows per page).
✅ Frequently Asked Questions (FAQ)
SELECT TOP 3 * FROM Employees; returns only the first 3 rows. MySQL and PostgreSQL use LIMIT, while Oracle uses FETCH FIRST n ROWS ONLY or ROWNUM to achieve the same result.SELECT TOP 5 * FROM Employees;. LIMIT is MySQL/PostgreSQL syntax: SELECT * FROM Employees LIMIT 5;. They do the same thing — only the syntax is different.SELECT * FROM Employees LIMIT 5; — this returns the first 5 rows. To get the top 5 by salary: SELECT * FROM Employees ORDER BY Salary DESC LIMIT 5;SELECT * FROM Employees WHERE ROWNUM <= 3;. Be careful — ROWNUM filters before ORDER BY, so always use a subquery when combining with ORDER BY. In Oracle 12c and later, use FETCH FIRST 3 ROWS ONLY instead.SELECT TOP 50 PERCENT * FROM Employees; returns the top half of rows. If the table has 10 rows, this returns 5 rows. This is a SQL Server-only feature — MySQL and PostgreSQL do not support it.SELECT * FROM Employees ORDER BY ID LIMIT 5 OFFSET 5;. The formula is: OFFSET = (page_number - 1) × rows_per_page.