codescracker


sql

SQL Select Distinct



« Previous Tutorial Next Tutorial »


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;

SQL SELECT DISTINCT Statement Example

Here is an example of SELECT DISTINCT Statement in SQL. Consider the table CUSTOMERS having the following records:

sql distinct

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.

sql select distinct statement

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:

sql select distinct

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test