WITH TIES (SQL Standard)
WITH TIES (SQL Standard) is a SQL clause in the SELECT Queries category. SQL standard: like LIMIT but includes ties. Returns n rows plus all rows that have the same sort value as the nth row. The syntax is SELECT ... FROM table ORDER BY col FETCH FIRST n ROWS WITH TIES;. It returns top rows with ties. A typical example: SELECT name, salary FROM employees ORDER BY salary DESC FETCH FIRST 3 ROWS WITH TIES; -- If salaries are: 100, 95, 95, 90, 85 -- Returns 4 rows: 100, 95, 95 (the two 95s are tied for 3rd) -- PostgreSQL 13+, Oracle 12c+, SQL Server -- Supported in: standard SQL, differs from LIMIT behavior A close relative is SELECT, which retrieves data from a table. The most fundamental SQL statement. A close relative is SELECT *, which selects all columns from a table. A close relative is SELECT DISTINCT, which returns only distinct (unique) values from the specified columns.