ProblemYou want to know whether table values are unique. SolutionUse HAVING in conjunction with COUNT( ). DiscussionDISTINCT eliminates duplicates but doesn't show which values actually were duplicated in the original data. You can use HAVING to find unique values in situations to which DISTINCT does not apply. HAVING can tell you which values were unique or nonunique. The following statements show the days on which only one driver was active, and the days on which more than one driver was active. They're based on using HAVING and COUNT( ) to determine which TRav_date values are unique or nonunique: mysql> SELECT trav_date, COUNT(trav_date) -> FROM driver_log -> GROUP BY trav_date -> HAVING COUNT(trav_date) = 1; +------------+------------------+ | trav_date | COUNT(trav_date) | +------------+------------------+ | 2006-08-26 | 1 | | 2006-08-27 | 1 | | 2006-09-01 | 1 | +------------+------------------+ mysql> SELECT trav_date, COUNT(trav_date) -> FROM driver_log -> GROUP BY trav_date -> HAVING COUNT(trav_date) > 1; +------------+------------------+ | trav_date | COUNT(trav_date) | +------------+------------------+ | 2006-08-29 | 3 | | 2006-08-30 | 2 | | 2006-09-02 | 2 | +------------+------------------+ This technique works for combinations of values, too. For example, to find message sender/recipient pairs between whom only one message was sent, look for combinations that occur only once in the mail table: mysql> SELECT srcuser, dstuser -> FROM mail -> GROUP BY srcuser, dstuser -> HAVING COUNT(*) = 1; +---------+---------+ | srcuser | dstuser | +---------+---------+ | barb | barb | | gene | tricia | | phil | barb | | tricia | gene | | tricia | phil | +---------+---------+ Note that this query doesn't print the count. The first two examples did so, to show that the counts were being used properly, but you can refer to an aggregate value in a HAVING clause without including it in the output column list. |