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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
Active Unfilled Prescriptions Query
00:00
5 left

Active Unfilled Prescriptions Query

EasySQL · PostgreSQL

Problem

Write a MySQL query to retrieve all active prescriptions for a patient at Gifthealth that have not yet been filled.

Use the provided schema and assume the target patient_id is 101. Treat any matching row in prescription_fills as evidence that a prescription has been filled.

Output

  1. Return one row per qualifying prescription with prescription_id, patient_id, medication_name, and prescribed_date.
  2. Include only active, unfilled prescriptions for patient 101.
  3. Order by prescribed_date ascending, then prescription_id ascending.

Schema

prescriptions
ColumnTypeDescription
prescription_idPKINTUnique prescription identifier
patient_idINTGifthealth patient identifier
prescription_statusVARCHAR(20)Current prescription status
medication_nameVARCHAR(120)Name of the prescribed medication
prescribed_dateDATEDate the prescription was issued
quantityINTQuantity prescribed
expires_onDATEPrescription expiration date
prescription_fills
ColumnTypeDescription
fill_idPKINTUnique fill record identifier
prescription_idINTPrescription associated with the fill
filled_atTIMESTAMPTimestamp when the prescription was filled
fill_statusVARCHAR(20)Status of the fill transaction
pharmacy_nameVARCHAR(120)Pharmacy that processed the fill
Tablesprescriptionsprescription_fills
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.