SQL SELECT DISTINCT statement is basically used to return only the distinct values. Here is the general form of the SELECT DISTINCT statement in SQL:
SELECT DISTINCT column_name,column_name FROM table_name;
Here is an example of SELECT DISTINCT Statement in SQL. Consider the table CUSTOMERS having the following records:
First, let's see how the following SQL SELECT query returns many duplicate salary records:
SELECT SALARY FROM CUSTOMERS ORDER BY SALARY;
This would produce the following result where salary 76000 and 86000 is coming twice-twice which is a duplicate record from the original table.
Now, let's use the SQL DISTINCT keyword (to filter the duplication) with the above SQL SELECT query statement and see the result:
SELECT DISTINCT SALARY FROM CUSTOMERS ORDER BY SALARY;
It will produce this result where we don't have any duplicate entry:
© Copyright 2021. All Rights Reserved.