Skip to main content

Posts

Showing posts with the label SELECT with DISTINCT

SELECT with DISTINCT

I f a query returns a result that contains duplicate rows, the duplicates can be removed to produce a result set  in which every row is unique.  To do this, include the clause DISTINCT after SELECT and before the  column list.  Caution needs to be present when using DISTINCT due to the fact that DISTINCT will  compare whole rows when processing.  In the case below, the query results in a set that includes duplicate  rows:  mysql> SELECT Continent FROM Country;  +--------------------+  | Continent          |  +--------------------+  | Asia                  |  | Europe             |  | North America |  | Europe             |  | Africa                |  | Oceania           |         ...       | Antarctica        |  | Oceania           |  +--------------------+  239 rows in set (#.## sec)  By adding DISTINCT to the statement, the duplicates are removed and only unique rows are returned:  mysql> SELECT DISTINCT Continent FROM Country;