The SELECT DISTINCT statement is used to return a unique different value.
SQL SELECT DISTINCT statement
In the table, a column may contain multiple duplicate values, and sometimes you may want to list only the distinct values.
The DISTINCT keyword is used to return a unique different value.
SQL SELECT DISTINCT syntax
SELECT DISTINCT column_name,column_name
FROM table_name;
FROM table_name;
In this tutorial, we will use the RUNOOB sample database.
The following is the data selected from the "Websites" table:
+ ---- + -------------- + --------------------------- + - ------ + --------- + | id | name | url | alexa | country | + ---- + -------------- + - -------------------------- + ------- + --------- + | 1 | Google | Https : //www.google.cm/ | 1 | USA | | 2 | Taobao | https : //www.taobao.com/ | 13 | CN | | 3 | Rookie Tutorial | http : //www.runoob.COM / | 4689 | CN | | 4 | Twitter | HTTP : //weibo.com/ | 20 | CN | | 5 | Facebook | HTTPS : //www.facebook.com/ | 3 | USA | + --- - + -------------- + --------------------------- + ----- - + --------- +
SELECT DISTINCT instance
The following SQL statement only from the "Websites" table "country" column to select a unique different value, that is, remove the "country" column repeat value:
Examples
SELECT DISTINCT country FROM Websites ;
Output results:
EmoticonEmoticon