mercredi 3 décembre 2014

Limit distinct count of group by


Suppose for simplicity that I have a table t with columns id and value. I can find the ids that have more than one distinct value using a query such as



SELECT id, COUNT(DISTINCT(value)) AS count
FROM t
GROUP BY id
HAVING count > 1


Is there a more efficient way to do this? Can it be changed so that the count for each id stops as soon as more than one distinct value is found for it?





Aucun commentaire:

Enregistrer un commentaire