WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL SELECT DISTINCT Statement


The SELECT DISTINCT statement is used to return only unique values.


SQL SELECT DISTINCT statement

In a table, a column may contain multiple duplicate values, and sometimes you may want to list only distinct values.

The

DISTINCT keyword is used to return only unique values.

SQL SELECT DISTINCT syntax

SELECT DISTINCT column_name,column_name
FROM table_name;


In this tutorial, we will use the welookups sample database.

Here is the data from the "Websites" table:

+----+--------------+---------------------------+-------+---------+
| id | name         | url                       | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1  | Google       | https://www.google.IN/  | 1     | USA     |
| 2  | Indiatimes          | https://www.Indiatimes.com/ |9   | IN      |
| 3  | zomato      | http://www.zomato.com/  | 83  | IN      |
| 4  | indiamart          | http://indiamart.com/       | 33    | IN      |
| 5  | Facebook     | https://www.facebook.com/| 3     | USA     |
+----+--------------+---------------------------+-------+---------+


SELECT DISTINCT example

The following SQL statement selects only unique values from the "country" column of the "Websites" table, that is, removes duplicate values from the "country" colume

Examples

SELECT DISTINCT country FROM Websites;