SQL Tutorial – Lesson 13

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.

💡 Real-world example: Show the top 5 highest-paid employees. Show the 10 most recent orders. Get the first 3 products in alphabetical order. All of these need a row-limiting clause combined with ORDER BY.

Sample Employees Table (used in all examples):-

Employees
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT9000Pune
3RAJSALES5000Delhi
4SUJANHR8000Pune
5MEENASALES12000Mumbai
6PRAMODIT15000Bangalore
7NILESHHR7000Mumbai

✅ 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;
ℹ️ Note: All four clauses achieve the same goal — limit rows returned — but the syntax differs by database. The examples below show each one clearly.

✅ Database Comparison – Which Clause to Use

DatabaseClause to UseExample
SQL Server / MS AccessSELECT TOP nSELECT TOP 3 * FROM Employees;
MySQL / MariaDBLIMIT nSELECT * FROM Employees LIMIT 3;
PostgreSQL / SQLiteLIMIT nSELECT * FROM Employees LIMIT 3;
Oracle 12c and laterFETCH FIRST n ROWS ONLYSELECT * FROM Employees FETCH FIRST 3 ROWS ONLY;
Oracle (older versions)WHERE ROWNUM <= nSELECT * FROM Employees WHERE ROWNUM <= 3;
DB2 / InformixFETCH FIRST n ROWS ONLYSELECT * 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:-

First 3 Rows Returned
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT9000Pune
3RAJSALES5000Delhi
4SUJANHR8000Pune
5MEENASALES12000Mumbai
6PRAMODIT15000Bangalore
7NILESHHR7000Mumbai
ℹ️ Explanation: Only rows 1, 2, and 3 (highlighted green) are returned. Rows 4–7 (greyed out) are not returned. The query stopped after fetching 3 rows.

✅ 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:-

First 3 Rows Returned
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT9000Pune
3RAJSALES5000Delhi
💡 Same result as TOP 3 — LIMIT 3 and SELECT TOP (3) both return the same first 3 rows. Only the syntax is different depending on your database.

✅ 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:-

Top 3 Highest Paid Employees
IDNameDepartmentSalaryCity
6PRAMODIT15000Bangalore
5MEENASALES12000Mumbai
1ANNIIT10000Mumbai
⚠️ Always use ORDER BY with TOP/LIMIT! Without ORDER BY, the "first 3 rows" depend on internal database storage order — which is unpredictable. Add 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):-

Top 50% of Employees by Salary
IDNameDepartmentSalaryCity
6PRAMODIT15000Bangalore
5MEENASALES12000Mumbai
1ANNIIT10000Mumbai
2POOJAIT9000Pune
ℹ️ Note: 50% of 7 rows = 3.5 — SQL Server rounds UP, so 4 rows are returned. TOP PERCENT is only available in SQL Server and MS Access. MySQL and PostgreSQL do not support PERCENT.

✅ 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:-

Top 3 Rows – FETCH FIRST
IDNameDepartmentSalaryCity
6PRAMODIT15000Bangalore
5MEENASALES12000Mumbai
1ANNIIT10000Mumbai
💡 Tip: 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:-

First 3 Rows – ROWNUM
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT9000Pune
3RAJSALES5000Delhi
🚨 Important: ROWNUM in Oracle assigns row numbers before ORDER BY is applied. To get top N by salary in older Oracle, you must wrap the query in a subquery:

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):-

Page 2 – Rows 4 to 6
IDNameDepartmentSalaryCity
4SUJANHR8000Pune
5MEENASALES12000Mumbai
6PRAMODIT15000Bangalore

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;
💡 Pagination formula: OFFSET = (page_number - 1) × rows_per_page
Page 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

❌ Mistake 1: Using TOP/LIMIT without ORDER BY
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.
❌ Mistake 2: Using LIMIT in SQL Server
SQL Server does NOT support LIMIT. Using LIMIT 3 in SQL Server will cause a syntax error. Use SELECT TOP (3) instead.
❌ Mistake 3: Using SELECT TOP in MySQL
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.
❌ Mistake 4: ROWNUM with ORDER BY in Oracle (wrong order)
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;
❌ Mistake 5: Forgetting OFFSET starts at 0, not 1
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)

What is the SQL SELECT TOP clause?
SELECT TOP is used in SQL Server and MS Access to return only a specified number of rows from a query result. For example, 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.
What is the difference between TOP and LIMIT in SQL?
Both TOP and LIMIT restrict how many rows a query returns, but for different databases. TOP is SQL Server syntax: 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.
How do I get the TOP N rows in MySQL?
MySQL does not support TOP. Use LIMIT instead: 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;
How do I use ROWNUM in Oracle SQL?
In older Oracle versions, use ROWNUM in a WHERE clause: 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.
What is SELECT TOP PERCENT in SQL Server?
SELECT TOP with PERCENT returns a percentage of rows. For example: 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.
How do I use LIMIT with OFFSET for pagination in SQL?
Use LIMIT with OFFSET to implement pagination. OFFSET specifies how many rows to skip. For page 2 (rows 6-10 when showing 5 per page): SELECT * FROM Employees ORDER BY ID LIMIT 5 OFFSET 5;. The formula is: OFFSET = (page_number - 1) × rows_per_page.

✍️ About the Author: Pramod Behera

Pramod Behera is a SAP and SQL educator with 10+ years of experience in enterprise software and database systems. He founded LearnToSAP.com to help beginners learn SAP and SQL concepts through clear, practical, real-world examples. His tutorials have helped thousands of students and IT professionals across India and beyond.