runtime
72 / 139

task LEFT JOIN · easy

Predict: patients with and without missed appointments

Predict every row returned when the six sample patients are LEFT JOINed to their cancelled or missed appointments.

what to return

Columns
patient_idstatus in this order
Rows
in the order asked
Watch for
Use only the sample rows shown. NULL is not zero or empty text. Keep duplicate rows.
Skill
Reason about the exact result of a fixed SQL query. Refresher: Keep unmatched rows →

data you can query

Healthcare dataset: the first 6 rows of each table. Under each column name: the kind of value it holds, and which table it links to. Your queries run on all rows.

patient_sample2 columns · 6 rows
patient_idinsurance_type
1medicaid
2medicare
3medicaid
4commercial
5medicaid
6medicare
patient_id
1
insurance_type
medicaid
patient_id
2
insurance_type
medicare
patient_id
3
insurance_type
medicaid
patient_id
4
insurance_type
commercial
patient_id
5
insurance_type
medicaid
patient_id
6
insurance_type
medicare

all 6 rows

missed_appointments3 columns · 8 rows
appointment_idpatient_idstatus
11cancelled
81cancelled
265cancelled
295cancelled
346no_show
356no_show
appointment_id
1
patient_id
1
status
cancelled
appointment_id
8
patient_id
1
status
cancelled
appointment_id
26
patient_id
5
status
cancelled
appointment_id
29
patient_id
5
status
cancelled
appointment_id
34
patient_id
6
status
no_show
appointment_id
35
patient_id
6
status
no_show

first 6 of 8 rows · your queries use all of them

predict.sql
SELECT p.patient_id, a.status
FROM patient_sample p
LEFT JOIN missed_appointments a ON a.patient_id = p.patient_id
ORDER BY p.patient_id, a.appointment_id
Read the query · predict its result
SELECT p.patient_id, a.status FROM patient_sample p LEFT JOIN missed_appointments a ON a.patient_id = p.patient_id ORDER BY p.patient_id, a.appointment_id

Look at the sample tables and SQL. Enter the rows you think the query returns, in this column order: patient_id, status. Put each row in square brackets, then wrap all rows in another pair of brackets (JSON format). For example, [[1,null]] is one row with 2 values. Replace these with your predicted values. Use numbers without quotes, text in double quotes, and null for SQL NULL. Keep repeated rows. Use [] for no rows. Keep rows in the order specified by ORDER BY.

Hints and the answer are always available. Using them counts the question as solved with help.

Predict: patients with and without missed appointments — SQL practice · Runtime