If I have a table where there are duplicate IDs, how can I count the number of times the same ID appears in the table and only show records that have a count greater than 1?
I’ve tried:
SELECT COUNT(ID) AS myCount FROM myTbl
WHERE myCount > 1 GROUP BY ID
But it says myCount is invalid column name. Can someone show me what I’m doing wrong?
You need to use the HAVING keyword:
From MSDN: