An extension to FETCH FIRST / LIMIT that includes additional rows that tie on the last ORDER BY value rather than cutting them off arbitrarily.
A modifier on TOP/LIMIT that includes additional rows that tie with the last returned row, useful for including all top-ranked results when the Nth and N+1st rows are tied. Prevents arbitrary cutoff of equal-ranked items.
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | ✗ Not Supported | — | WITH TIES is not supported. Workaround: use RANK() in a subquery and filter WHERE rnk <= n. |
| PostgreSQL | ✓ Supported | 13 | FETCH FIRST n ROWS WITH TIES added in PostgreSQL 13. |
| SQL Server | ✓ Supported | 2008 | Supported via SELECT TOP n WITH TIES. Requires an ORDER BY clause. |
| Oracle | ✓ Supported | 12c | Supported in the FETCH FIRST syntax introduced in 12c. |
| SQLite | ✗ Not Supported | — | WITH TIES is not supported. Use a RANK() window function in a subquery as a workaround. |
WITH TIES is handy for leaderboards and ranking queries where arbitrary tie-breaking at the boundary is undesirable. SQL Server's TOP n WITH TIES syntax predates the standard FETCH FIRST form. PostgreSQL added it relatively late (13). MySQL and SQLite both lack it entirely — the portable workaround is consistent across all engines: wrap with RANK() OVER (ORDER BY col) and filter WHERE rnk <= n in an outer query. Note that WITH TIES can return more rows than n — an important consideration for pagination or when a caller assumes a fixed row count.
FETCH FIRST n ROWS WITH TIES added in PostgreSQL 13.
Supported via SELECT TOP n WITH TIES. Requires an ORDER BY clause.
Supported in the FETCH FIRST syntax introduced in 12c.