Selecting the top 10 rows in SQL is one of the first skills every database learner needs, yet it is also one of the most misunderstood. SQL Server uses TOP, MySQL and PostgreSQL use LIMIT, Oracle uses FETCH FIRST, and standard SQL has its own syntax. The reason is simple: SQL has no single universal “top 10” command. Also, more importantly, “top” only has meaning when you define an order. Without an ORDER BY clause, the database is free to return any 10 rows it finds first, which may change from one query to the next.
Why “Top 10” Depends on Your Database
SQL is standardized, but vendors add their own shortcuts for limiting result sets. That said, the concept is the same everywhere: return only the first 10 rows from a query result. The syntax changes because each database engine evolved separately.
Here is the quick reference:
- SQL Server:
SELECT TOP 10 ... - MySQL:
SELECT ... LIMIT 10 - PostgreSQL:
SELECT ... LIMIT 10 - SQLite:
SELECT ... LIMIT 10 - Oracle 12c and later:
SELECT ... FETCH FIRST 10 ROWS ONLY - Standard SQL:
SELECT ... FETCH FIRST 10 ROWS ONLY - DB2:
SELECT ... FETCH FIRST 10 ROWS ONLY
If you remember only one rule, remember this: the limit clause belongs at the end of the query, after FROM, WHERE, GROUP BY, HAVING, and ORDER BY It's one of those things that adds up..
The Golden Rule: Always Use ORDER BY
A query like this returns 10 rows, but not necessarily the 10 rows you expect:
SELECT *
FROM employees
LIMIT 10;
Those rows might be the first 10 physically stored rows, the first 10 returned by an index, or the first 10 produced by a parallel scan. The result is not guaranteed to be stable. If you want the top 10 highest salaries, the 10 newest orders, or the 10 most recent sign-ups, you must specify the order.
You'll probably want to bookmark this section Not complicated — just consistent..
SELECT *
FROM employees
ORDER BY salary DESC
LIMIT 10;
The ORDER BY salary DESC clause tells the database to sort from highest to lowest. The LIMIT 10 clause then keeps only the first 10 rows of that sorted result. This combination is what most people mean by “top 10 rows in SQL.
How to Select Top 10 Rows in SQL Server
SQL Server uses the TOP keyword immediately after SELECT. The safest form places the number in parentheses:
SELECT TOP (10) *
FROM employees
ORDER BY salary DESC;
You can also use TOP 10 without parentheses, but parentheses make the intent clearer and are required in some contexts. SQL Server also supports TOP with a percentage:
SELECT TOP (10) PERCENT *
FROM employees
ORDER BY salary DESC;
That returns approximately the top 10 percent of rows, not 10 rows. Another useful option is WITH TIES:
SELECT TOP (10) WITH TIES *
FROM employees
ORDER BY salary DESC;
WITH TIES includes rows that tie with the last row in the top 10. If the 10th and 11th employees both earn the same salary, both may be returned. This is helpful when ranking by a column that contains duplicate values.
How to Select Top 10 Rows in MySQL and PostgreSQL
MySQL and PostgreSQL use LIMIT. The basic pattern is:
SELECT *
FROM employees
ORDER BY salary DESC
LIMIT 10;
MySQL also allows LIMIT offset, count. To give you an idea, to skip the first 20 rows and return the next 10:
SELECT *
FROM employees
ORDER BY salary DESC
LIMIT 20, 10;
PostgreSQL uses a clearer form:
SELECT *
FROM employees
ORDER BY salary DESC
LIMIT 10 OFFSET 20;
The OFFSET clause is useful for pagination, but it becomes slower on large tables because the database still has to scan and discard the skipped rows. For deep pagination, keyset pagination is often faster.
How to Select Top 10 Rows in Oracle
Modern Oracle databases support the standard FETCH FIRST syntax:
SELECT *
FROM employees
ORDER BY salary DESC
FETCH FIRST 10 ROWS ONLY;
Older Oracle versions used ROWNUM, which is trickier because ROWNUM is assigned before sorting. A common workaround is to sort in a subquery first:
SELECT *
FROM (
SELECT *
FROM employees
ORDER BY salary DESC
)
WHERE ROWNUM <= 10;
If you are using Oracle 12c or later, prefer FETCH FIRST. It is cleaner and less error-prone.
Selecting Top 10 by a Specific Column
The most
The most common use case is ordering by a numeric column like salary, price, or score, but the same pattern applies to any sortable data type. To find the ten most recent sign-ups, order by a timestamp column:
SELECT *
FROM users
ORDER BY created_at DESC
LIMIT 10;
For the ten earliest orders, use ascending order:
SELECT *
FROM orders
ORDER BY order_date ASC
LIMIT 10;
When sorting by text columns, the database uses the column’s collation rules. To get the last ten customers alphabetically:
SELECT *
FROM customers
ORDER BY last_name DESC
LIMIT 10;
If you need a deterministic result when the sort column contains duplicates, add a tie-breaker. As an example, to get the top ten salaries and break ties by hiring the most senior employee first:
SELECT *
FROM employees
ORDER BY salary DESC, hire_date ASC
LIMIT 10;
Without the second sort key, the order of tied rows is undefined and may change between executions Simple as that..
Performance Considerations
ORDER BY combined with LIMIT (or TOP / FETCH) is efficient when an index exists on the sort column. Think about it: the database can scan the index in reverse order and stop after ten entries. Without an index, the database must sort the entire table—an expensive operation on large datasets.
For pagination deeper than the first few pages, OFFSET performance degrades linearly. A common optimization is keyset pagination (also called seek method), which filters by the last seen value instead of skipping rows:
SELECT *
FROM employees
WHERE salary < 95000
ORDER BY salary DESC
LIMIT 10;
This avoids the OFFSET scan entirely and remains fast regardless of page depth Small thing, real impact..
Conclusion
Selecting the top 10 rows is a fundamental SQL task, but the syntax varies across database engines. PostgreSQL, MySQL, and SQLite rely on LIMIT; SQL Server uses TOP; modern Oracle adopts the standard FETCH FIRST. Plus, regardless of dialect, the logic remains the same: define a clear sort order with ORDER BY, then restrict the result set. Pair this pattern with appropriate indexes, and consider keyset pagination for deep result sets, to keep queries fast and predictable at any scale No workaround needed..
The official docs gloss over this. That's a mistake.