SQL SELECT Distinct : Statement



SQL SELECT DISTINCT Statement :

  1. Suppose we need all the rows that are unique then we need to use distinct statement.
  2. Sometimes column may contain the duplicate values then we can select only distinct values.
  3. The DISTINCT keyword can be used to return only distinct (different) values.

Syntax :

SQL> SELECT DISTINCT column_name,column_name FROM table_name;

Select distinct rows :

Consider following “CUSTOMER” table –

IDNAMEAGEADDRESSSALARY
1Raj20Pune1000.00
2Saurabh20Pune6000.00
3Omkar24Mumbai4000.00
4Anand23Nagpur3000.00
5Anmol29Goa1000.00
6Poonam25Delhi9000.00

Now suppose we want only addresses that are unique then we can use following query –

SQL> Select distinct ADDRESS from CUSTOMER

Program will give following output –

ADDRESS
Pune
Mumbai
Nagpur
Goa
Delhi