TOP
row limiter; without ORDER BY the chosen rows are not deterministic
What changes
- Input
- rows after ORDER BY (or affected rows for DML)
- Output or change
- first N or N percent rows
Syntax at a glance
[ TOP (expression) [ PERCENT ] [ WITH TIES ] ]
Work example
A review screen needs a fixed number of highest scores with equal scores at the cutoff retained.
Run the sample with ORDER BY and WITH TIES. Remove WITH TIES and compare the last score group.
Check your work TOP. The result contains 9, 7, and 7. TOP without ORDER BY has no stable row choice.
Practice SQL
Open in SQL FlowSELECT TOP (2) WITH TIES Score
FROM (VALUES (9), (7), (7), (4)) AS Scores(Score)
ORDER BY Score DESC;
Open Microsoft Learn for full syntax, permissions, and details for your version.