Can someone tell me what I’m doing wrong here and how to make the query work?
I’m trying to return {OrgID, IdentifierTypeID, IdentifierOrder, ValidFrom} for all records where those 4 columns are duplicated along with the count of duplicates. I only want duplicates shown in the result set, that’s why I tried the > 1 part.
select count(*) Number, OrgID, IdentifierTypeID, IdentifierOrder, ValidFrom
from xdb.dbo.OrganizationIdentifier_IngestII
where Number > 1
group by OrgID, IdentifierTypeID, IdentifierOrder, ValidFrom
You use a HAVING clause to test the result of an aggregate function. Also, you cannot use the column alias (Number) in that test, so you’ll need to repeat the function.