Tom Dawn - 4 months ago 20

MySQL Question

Answer

```
SELECT cid
FROM yourTable
GROUP BY cid
HAVING COUNT(*) - COUNT(DISTINCT pid) > 0
```

**Explanation:**

This query will identify `cid`

groups which have a `pid`

value appearing twice or more, for at least one `pid`

value. The logic in the `HAVING`

clause is that if all `pid`

are unique for a `cid`

group, then the expression will equal zero, otherwise it will be greater than zero.