Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Overlapping Appointments
00:00
5 left

Overlapping Appointments

MediumSQL · PostgreSQL

Problem

Providence uses appointment data from its electronic health record to identify patients who were scheduled for overlapping encounters. Write a PostgreSQL query that reports each overlapping appointment pair for March 10, 2025.

Requirements

  1. Consider only appointments with status scheduled, checked_in, or completed.
  2. Treat two appointments as overlapping when one starts before the other ends and the other starts before the first ends. Appointments that only touch at an endpoint do not overlap.
  3. Return each pair once, excluding self-pairs and reversed duplicates.
  4. Include patient details, both appointment intervals, both provider names, and the overlap duration in minutes.
  5. Preserve an overlap even when a provider is missing, and sort by patient ID, first appointment start time, and second appointment start time.

Schema

patients
ColumnTypeDescription
patient_idPKINTUnique patient identifier
first_nameVARCHAR(50)Patient first name
last_nameVARCHAR(50)Patient last name
providers
ColumnTypeDescription
provider_idPKINTUnique provider identifier
provider_nameVARCHAR(100)Provider display name
specialtyVARCHAR(80)Clinical specialty
appointments
ColumnTypeDescription
appointment_idPKINTUnique appointment identifier
patient_idINTPatient receiving the appointment
provider_idINTAssigned provider
appointment_dateDATECalendar date of the appointment
start_timeTIMESTAMPAppointment start timestamp
end_timeTIMESTAMPAppointment end timestamp
statusVARCHAR(20)Appointment lifecycle status
Tablesappointmentspatientsproviders
Interviewer

Your question is Overlapping Appointments. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.