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_idstatusin 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_id | insurance_type |
|---|---|
| 1 | medicaid |
| 2 | medicare |
| 3 | medicaid |
| 4 | commercial |
| 5 | medicaid |
| 6 | medicare |
- 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_id | patient_id | status |
|---|---|---|
| 1 | 1 | cancelled |
| 8 | 1 | cancelled |
| 26 | 5 | cancelled |
| 29 | 5 | cancelled |
| 34 | 6 | no_show |
| 35 | 6 | no_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
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
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.