Write a SOQL query to find duplicate Contacts based on the Email field (SELECT Email, COUNT(Id) FROM Contact GROUP BY Email HAVING COUNT(Id) > 1).
Answer
Group by Email and keep groups with more than one row.
soql
SELECT Email, COUNT(Id) cnt FROM Contact
WHERE Email != null
GROUP BY Email
HAVING COUNT(Id) > 1
Each result row is an AggregateResult giving the duplicate email and how many times it appears.
soqlscenarioaggregateduplicates