TOP ... WITH TIES
TOP WITH TIES
What changes
- Input
- ordered rows
- Output or change
- N rows plus peers equal to the last row's sort key
Syntax at a glance
TOP ( expression ) [ PERCENT ] WITH TIES ... ORDER BY ...
Work example
A top-N report must keep every row tied with the last ordered value.
Create a tie at the cutoff and compare the result with and without WITH TIES.
Check your work TOP ... WITH TIES. All rows tied on the final ORDER BY value remain, even when the result has more than N rows.
Open Microsoft Learn for full syntax, permissions, and details for your version.