Reputation: 23379
How can I select the distinct values from table
.col
where the value of table
.col
is not unique.
Consider the example table on this page: (w3schools)
I want to return a list of countries where there's more than 1 customer. In this case it would return only "Mexico".
I am currently using 1 query to get the distinct values, then looping through and checking the number of occurrences with another query. Can this be done with a single query?
Upvotes: 2
Views: 1543
Reputation: 1427
Use HAVING
and GROUP BY
SELECT country FROM customers GROUP BY country HAVING Count(*)>1
Upvotes: 5