Database Reference
In-Depth Information
3.4. Removing Duplicate Rows
Problem
Output from a query contains duplicate rows. You want to eliminate them.
Solution
Use DISTINCT .
Discussion
Some queries produce results containing duplicate rows. For example, to see who sent
mail, query the mail table like this:
mysql> SELECT srcuser FROM mail;
+---------+
| srcuser |
+---------+
| barb |
| tricia |
| phil |
| barb |
| gene |
| phil |
| barb |
| tricia |
| gene |
| phil |
| gene |
| gene |
| gene |
| phil |
| phil |
| gene |
+---------+
That result is heavily redundant. To remove the duplicate rows and produce a set of
unique values, add DISTINCT to the query:
mysql> SELECT DISTINCT srcuser FROM mail;
+---------+
| srcuser |
+---------+
| barb |
| tricia |
| phil |
| gene |
+---------+
To count the number of unique values in a column, use COUNT(DISTINCT) :
Search WWH ::




Custom Search