SQL SELECT Distinct : Statement
SQL SELECT DISTINCT Statement :
- Suppose we need all the rows that are unique then we need to use distinct statement.
- Sometimes column may contain the duplicate values then we can select only distinct values.
- 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 -
ID | NAME | AGE | ADDRESS | SALARY |
---|---|---|---|---|
1 | Raj | 20 | Pune | 1000.00 |
2 | Saurabh | 20 | Pune | 6000.00 |
3 | Omkar | 24 | Mumbai | 4000.00 |
4 | Anand | 23 | Nagpur | 3000.00 |
5 | Anmol | 29 | Goa | 1000.00 |
6 | Poonam | 25 | Delhi | 9000.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 |