Home › Interview Questions › Given a table with columns ID, student, name, and …

Given a table with columns ID, student, name, and email, how would you handle duplicate names?

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

💡 Model Answer

Duplicate names are a common data quality issue, especially when the name column is not unique. First, identify duplicates with a query such as SELECT name, COUNT() FROM students GROUP BY name HAVING COUNT() > 1. Once identified, decide on a strategy: 1) Keep only one record and merge data, 2) Keep all records but add a distinguishing suffix or surrogate key, or 3) Reject duplicates by adding a UNIQUE constraint on a combination of columns that should be unique, such as (name, email). In many systems, email is a better unique identifier, so you might enforce a UNIQUE constraint on email and allow duplicate names. If you need to preserve all rows, you can add a surrogate ID (e.g., a UUID) and use a separate lookup table for names. When cleaning data, you can use window functions like ROW_NUMBER() OVER (PARTITION BY name ORDER BY id) to flag duplicates and then decide which row to keep. The key is to understand the business rule: are names truly unique, or do you need to differentiate by other attributes?

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