DISTINCT clause | SQL Tutorial and Query Example

Text copied!

DISTINCT clause


  • DISTINCT clause :

    DISTINCT clause is used to eliminate the duplicate rows from the result.

    The syntax of the DISTINCT clause generally looks like this :
    Here's an example of how you might use the DISTINCT clause :

    Suppose we have a table called [Employees] table that contains duplicate rows.

    Case - 1 :

    Let's assume you want to retrieve all columns with only unique rows by eliminating duplicate rows from [Employees] table.

    SELECT DISTINCT column_name(s)
    FROM table_name;
            
    Case - 2 :

    Let's assume you want to retrieve only Employee_Id column with unique rows by eliminating duplicate rows from [Employees] table.

    DISTINCT clause
    SELECT DISTINCT *
    FROM [Employees];
            
    DISTINCT clause
    SELECT DISTINCT Employee_Id
    FROM [Employees];
            
    DISTINCT clause

    Frequently Asked Questions :

    The DISTINCT clause removes duplicate rows from the result set in SQL.
    The DISTINCT rule in SQL removes duplicate rows from the result set of a query.
    Using DISTINCT in SQL can impact performance by requiring additional processing to identify and remove duplicates.
    No, DISTINCT cannot be used directly in a WHERE clause; it's used in the SELECT clause to filter duplicate rows in the result set.