# 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).

**Topic:** Development · **Difficulty:** Medium · **Asked at:** Accenture, Infosys, PwC, EY · **Tags:** soql, scenario, aggregate, duplicates

Read it on the site: https://www.forcechallenges.com/interview-questions/write-a-soql-query-to-find-duplicate-contacts-based-on-the-email-field-select-email-count-id-from-contact

## 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.

---
Source: ForceChallenges · last updated 2026-10-19
