Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find Duplicate Names

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

Your question is Find Duplicate Names. 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

Epsilon's employee directory contains a non-unique name column. Write a PostgreSQL query that identifies names appearing more than once and summarizes the matching employees by department.

Requirements

  1. Exclude rows where name is NULL, because they do not represent a usable employee name.
  2. Return each duplicated name and the total number of employees using that name.
  3. Include a comma-separated, alphabetically ordered list of associated department names. Preserve duplicate-name employees whose department is not assigned.
  4. Sort the final result alphabetically by employee name.

Schema

emp
ColumnTypeDescription
employee_idPKINTEGERUnique employee identifier
nameVARCHAR(100)Employee display name, which may be duplicated
department_idINTEGERAssigned department identifier
departments
ColumnTypeDescription
department_idPKINTEGERUnique department identifier
department_nameVARCHAR(100)Epsilon department name
Tablesempdepartments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results