Latest web development tutorials

SQL SELECT DISTINCT statement

SELECT DISTINCT statement is used to return only difference values.


SQL SELECT DISTINCT statement

In the table, a column might contain multiple duplicate values, sometimes you may want to just list the different (distinct) values.

DISTINCT keyword is used to return only difference values.

SQL SELECT DISTINCT syntax

SELECT DISTINCT column_name , column_name
FROM table_name ;


In this tutorial, we will use w3big sample database.

The following is a selected "Websites" table data:

+----+--------------+---------------------------+-------+---------+
| id | name         | url                       | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1  | Google       | https://www.google.cm/    | 1     | USA     |
| 2  | 淘宝          | https://www.taobao.com/   | 13    | CN      |
| 3  | 本教程      | http://www.w3big.com/    | 4689  | CN      |
| 4  | 微博          | http://weibo.com/         | 20    | CN      |
| 5  | Facebook     | https://www.facebook.com/ | 3     | USA     |
+----+--------------+---------------------------+-------+---------+


SELECT DISTINCT examples

The following SQL statement only "country" column "Websites" list select the only different values, that is, to remove the "country" duplicate column values:

Examples

SELECT DISTINCT country FROM Websites;

Output: