Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Use FULL JOIN for Complete Coverage

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

Your question is Use FULL JOIN for Complete Coverage. 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

IBM HR Analytics needs a reconciliation report between employee assignments and the department master data. Write a PostgreSQL query using a FULL JOIN so that no employee or department record is omitted.

Requirements

  1. Return employee ID, employee name, department ID, and department name.
  2. Use COALESCE to display the department ID from whichever table contains it.
  3. Add a record_status column identifying Matched, Unmatched employee, or Unmatched department.
  4. Sort by department ID ascending, then employee ID ascending, with null values last.

Schema

employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(100)Employee full name
department_idINTAssigned department identifier
job_titleVARCHAR(100)Employee job title
departments
ColumnTypeDescription
department_idPKINTUnique department identifier
department_nameVARCHAR(100)Department name
locationVARCHAR(100)Department office location
Tablesemployeesdepartments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results