SQL Flow Field Guide

TOP ... WITH TIES

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

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.