Home › Interview Questions › How would you use a self‑join on the customers tab…

How would you use a self‑join on the customers table to find duplicate verified records by matching normalized emails?

🟡 Medium Conceptual Junior level
1Times asked
Jul 2026Last seen
Jul 2026First seen

💡 Model Answer

To find duplicate verified customers by email you can join the table to itself on the normalized email column. First, normalize the email by trimming whitespace and converting to lower case: LOWER(TRIM(email)). Then join the table c1 to c2 on that normalized email, filter both sides for verification_status = 'verified', and enforce c1.id < c2.id to avoid duplicate pairs and self‑joins. The query looks like:

sql
SELECT c1.id AS id1, c2.id AS id2, c1.email
FROM customers c1
JOIN customers c2
  ON LOWER(TRIM(c1.email)) = LOWER(TRIM(c2.email))
WHERE c1.verification_status = 'verified'
  AND c2.verification_status = 'verified'
  AND c1.id < c2.id;

This returns each pair of verified customers that share the same email. You can then decide how to handle the duplicates (e.g., merge, flag, or delete).

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500