• Teach Your Self With
             w3htmlschool.com

MySQL DISTINCT clause

MYSQL Distinct remove duplicate row from the table when you use with select clause

Syntax


SELECT DISTINCT
columns
FROM
table_name
WHERE
where_conditions;
Table
For the example country table is used .The structure of country table is as follow:
+----------------+------------+
| Field | Type |
+----------------+------------+
| Code | char(3) |
| Name | char(52) |
| Continent | char(40) |
| Region | char(26) |
| SurfaceArea | float(10,2)|
| IndepYear | smallint(6)|
| Population | int(11) |
| LifeExpectancy | float(3,1) |
| GNP | float(10,2)|
| GNPOld | float(10,2)|
| LocalName | char(45) |
| GovernmentForm | char(45) |
| HeadOfState | char(60) |
| Capital | int(11) |
| Code2 | char(2) |
+----------------+------------+
Example
Select Distinct continent from country ;
Output
mysql> Select Distinct continent from country ;
+---------------+
| continent |
+---------------+
| Asia |
| Europe |
| North America |
| Africa |
| Oceania |
| South America |
| Antarctica |
+---------------+
7 rows in set (0.07 sec)