SQL SELECT TOP Clause

SQL SELECT TOP Clause
Here’s a clear and practical guide to the SQL SELECT TOP Clause, including differences across database engines.
Basic Usage (SQL Server / MS Access)
This returns the first 10 rows based on the default ordering (or a specified ORDER BY).
SELECT TOP with ORDER BY
Always combine with ORDER BY to ensure predictable results:
SELECT TOP with PERCENT
Returns a percentage of rows:
Other Databases Don’t Use TOP
Different SQL engines use different syntax:
PostgreSQL / MySQL / SQLite — Use LIMIT
Oracle — Use FETCH FIRST
Best Practices
- Always pair TOP/LIMIT with an ORDER BY
- Avoid using TOP without specifying sorting (non-deterministic)
- For pagination, use OFFSET + LIMIT (PostgreSQL/MySQL/SQLite) or OFFSET with FETCH (SQL Server/Oracle)
