SQL WITH TIES | SQL Tutorial and Query Example

Text copied!

SQL WITH TIES


  • Here's the syntax for using WITH TIES :
    Here's an example of how to use WITH TIES in a SQL query :

    1. Let assume you have a table called Employees with columns like Employee_id, Employee_Name, Gender, Salary, and Joining_Date.

    SELECT TOP n WITH TIES column1, column2, column3 ...
    FROM table_name
    ORDER BY column_name DESC;
            
    SQL WITH TIES
    SELECT 
    	TOP 2 WITH TIES
    	Employee_id, Employee_Name, Gender, Salary, Joining_Date
    FROM [Employees]
    ORDER BY Salary DESC;
            
    SQL WITH TIES
    SELECT 
    	TOP 2 
    	Employee_id, Employee_Name, Gender, Salary, Joining_Date
    FROM [Employees]
    ORDER BY Salary DESC;
            
    SQL WITH TIES

    Frequently Asked Questions :

    SQL with ties refers to retrieving additional rows that share the same value as the last row in an ordered result set.
    Top 10 with ties in SQL retrieves the top 10 rows from a result set, including additional rows if they share the same value as the 10th row.
    Select top 1 with ties means retrieving the top row from a result set, including additional rows if they share the same value as the top row.
    Percentage with ties in SQL involves retrieving a specified percentage of rows from a result set, including additional rows if they share the same value as the last row in the specified percentage.