Find First Occurrence of Duplicate Records

Find the first occurrence of each duplicate record.

sql

SELECT MIN(id) AS first_id, name, email FROM users GROUP BY name, email HAVING COUNT(*) > 1;

This query groups records by the specified columns and retrieves the minimum unique identifier for each set of duplicates, effectively identifying the first occurrence of each duplicated entry.

PromptDB can make mistakes. Please double-check responses.