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
SQL Table Operations and Debugging
00:00
5 left

SQL Table Operations and Debugging

MediumSQL · PostgreSQL

Problem

Tell me about a time you used SQL to insert data, union results, and debug a query involving specific column names.

Write a PostgreSQL query that inserts completed inpatient and outpatient encounters into the unified table and returns the inserted rows. Ensure the target's required identifier is populated and use the exact source and target column names.

Output

  1. One row per newly inserted encounter.
  2. Columns: activity_id, encounter_id, patient_id, activity_date, and source_system.
  3. Exclude non-completed source records and sort by source_system, activity_date, and activity_id ascending.

Schema

inpatient_encounters
ColumnTypeDescription
encounter_idPKINTInpatient encounter identifier
patient_idVARCHAR(20)Patient identifier
admit_dateDATEInpatient admission date
statusVARCHAR(20)Inpatient encounter status
outpatient_visits
ColumnTypeDescription
encounter_idPKINTOutpatient encounter identifier
patient_idVARCHAR(20)Patient identifier
visit_dateDATEOutpatient visit date
statusVARCHAR(20)Outpatient visit status
unified_encounters
ColumnTypeDescription
activity_idPKINTRequired unified activity identifier
encounter_idINTSource encounter identifier
patient_idVARCHAR(20)Patient identifier
activity_dateDATEUnified activity date
source_systemVARCHAR(20)Originating source system
Tablesinpatient_encountersoutpatient_visitsunified_encounters
Interviewer

Your question is SQL Table Operations and Debugging. 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.