I have a table containing duplicates of records. These duplicates are grouped in duplicate groups and also have an index (recordnumber) within the corresponding group. In the relevant table I have all records, even those which are not duplicates.
I need to select only those records, which have a minimum of 2 entries in a aduplicate group. so I used count, group by and having.
the issue is that I get strange result when doing so. The following screenshot shows all records including those with only one entry in a duplicate group. There are about 10k groups containing 2 or more duplicates
The issue is that as soon I uncomment the commented section, I only get 16 records instead of all with > 1 entries in a group and only groupid's 2 to 8...
does anybody see what I am missing here?
SELECT new_firstname AS firstname,
new_lastname AS lastname,
DubGroupID AS groupid,
RecNumberInDupGroup AS recnr_ingroup
FROM [SOMETABLE]
WHERE BatchCheckJobID = '59aae39d7ee949fc8c9cce2a5efc2a5e'
AND DubGroupID IN (SELECT COUNT(DubGroupID)
FROM [SOMETABLE]
GROUP BY DubGroupID
HAVING COUNT(DubGroupID) > 1)
ORDER BY groupid,
recnr_ingroup ASC;
Any hint is highly appreciated.


and DubGroupID in (select DubGroupID FROM [SOMETABLE]...