Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Finding Duplicate SQL Records

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Finding Duplicate SQL Records. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

EAB Navigate stores advising interactions submitted by advisors. Data quality analysts need to identify repeated interaction records before these records are used in advising activity reports.

Write a PostgreSQL query that finds duplicate rows in advising_interactions. Two interactions are duplicates when they have the same student_id, advisor_id, interaction_date, channel, and topic. The interaction_id is a unique row identifier and must not be part of the duplicate definition.

Requirements

  1. Use a CTE to identify duplicate combinations with COUNT(*) > 1.
  2. Return every source row belonging to a duplicate group, including its interaction_id and duplicate count.
  3. Join to students to display the student name. Preserve duplicate interactions even when no student record exists.
  4. Treat duplicate rows with a NULL topic as belonging to the same duplicate group, and order results by student ID, interaction date, and interaction ID.

Schema

advising_interactions
ColumnTypeDescription
interaction_idPKINTUnique interaction row identifier
student_idINTEAB student identifier
advisor_idINTAdvisor identifier
interaction_dateDATEDate of the advising interaction
channelVARCHAR(30)Interaction channel
topicVARCHAR(100)Advising topic
students
ColumnTypeDescription
student_idPKINTStudent identifier
first_nameVARCHAR(50)Student first name
last_nameVARCHAR(50)Student last name
Tablesadvising_interactionsstudents
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results