SQL Distinct Clause

DISTINCT command is used to get the unique value from the table. it is not considered duplicate value. It is used with SELECT Statement

Syntax:-


SELECT DISTINCT column_name FROM table_name

Example:- Suppose the employees table has 6 records


+----+------------+-----------+----------------+------------+
| id | first_name | last_name | email          | city       |
+----+------------+-----------+----------------+------------+
|  1 | John       | Tailor    | john@abc.com   | California |
|  2 | Rom        | Tailor    | rom@abc.com    | California |
|  3 | Andrew     | Symonds   | andrew@abc.com | Sydney     |
|  4 | Miacle     | clerk     | miacle@abc.com | sydney     |
|  5 | Sachin     | Tendulkar | sachin@abc.com | Mumbai     |
|  6 | Virat      | Kohli     | virat@abc.com  | delhi      |
+----+------------+-----------+----------------+------------+

Now, we need to get the unique city name.


SELECT DISTINCT city FROM employees

Output:-


+----+-------
| city       |
+----+--------
| California |
| Sydney     |
| Mumbai     |
| delhi      |
+----+--------