Sometimes you don’t want the whole table — you want the first handful of rows: the 10 newest orders, the 5 priciest products, a quick peek at what a query returns. SQL Server’s SELECT TOP does exactly that, capping the number of rows a query hands back. Other databases spell it LIMIT or FETCH FIRST, but the idea is the same.
The playground below runs a real SQL engine in your browser — and it understands both TOP and LIMIT, so you can try each.
Try it — cap the row count
Sample tables you can query
Retrieving a specific number of rows
SELECT TOP n returns at most n rows. In SQL Server, TOP comes right after SELECT:
SELECT TOP 10 *
FROM customers;Without an ORDER BY, “top 10” just means “the first 10 the database happens to return” — an arbitrary order you shouldn’t rely on. Which brings us to the important part.
TOP is only meaningful with ORDER BY
“Top” implies a ranking, and ranking means sorting. Pair TOP with ORDER BY to get a deterministic top-N — the actual highest or lowest by some column:
SELECT TOP 5 name, price
FROM products
ORDER BY price DESC;That’s the five most expensive products. Flip to ASC for the five cheapest. Without the ORDER BY, the same TOP 5 could return any five rows.
Top-N with ORDER BY
Sample tables you can query
The same idea in every database
Row limiting is one of the few places SQL dialects genuinely differ. The concept is identical; the keyword isn’t:
| Database | Syntax |
|---|---|
| SQL Server / MS Access | SELECT TOP 5 * FROM products |
| MySQL / PostgreSQL / SQLite | SELECT * FROM products LIMIT 5 |
| Oracle / standard SQL | SELECT * FROM products FETCH FIRST 5 ROWS ONLY |
| MySQL / PostgreSQL (with offset) | ... LIMIT 5 OFFSET 10 |
LIMIT and TOP both run in this playground — try switching between them:
TOP vs LIMIT — same result
Sample tables you can query
Percentages and ties (SQL Server)
Two SQL Server extras worth knowing, both syntax-only here:
TOP n PERCENTreturns that percentage of the rows instead of a fixed count:SELECT TOP 20 PERCENT * FROM customers ORDER BY signup_date DESC.WITH TIESincludes any rows that tie with the last one on theORDER BYvalue — soTOP 3 ... WITH TIESmight return four rows if two share third place. Without it, ties are broken arbitrarily. Add extraORDER BYcolumns to make the order fully deterministic.
Practice
Return the 3 cheapest products. Select name and price. (Sort by price, then keep only 3.)
Sample tables you can query
Return the 5 most recent orders by order_date. Select product and order_date.
Sample tables you can query
Frequently asked questions
What does SELECT TOP do in SQL? It limits a query to at most n rows — SELECT TOP 10 * FROM customers returns ten rows. It’s SQL Server / MS Access syntax.
What is the equivalent of SELECT TOP in MySQL or PostgreSQL? LIMIT: SELECT * FROM customers LIMIT 10. Oracle and standard SQL use FETCH FIRST 10 ROWS ONLY.
Do I need ORDER BY with TOP? For a meaningful “top N,” yes. Without ORDER BY, the database returns an arbitrary set of rows; with it, you get the genuine highest or lowest by your chosen column.
How do I get rows 11–20 (pagination)? Combine a limit with an offset: LIMIT 10 OFFSET 10 in MySQL/PostgreSQL, or OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY in SQL Server / standard SQL.
From a quick peek to a real pipeline
TOP and LIMIT are how you sample data fast while exploring. When exploration becomes a repeatable flow across sources, ET1 gives every node a live preview — you see the first rows of each step as you build, no TOP required.
Keep building: start with the SELECT statement, filter with WHERE, or sort and range-filter with BETWEEN.