Every query starts with SELECT (which columns) and FROM (which table). WHERE keeps the rows that match a condition.
SELECT encounter_id, patient_id, admit_date
FROM hd_encounters
WHERE encounter_type = 'inpatient';
Three habits matter on health data:
- Text comparisons are case-sensitive: the data says
inpatient, not Inpatient.
- An empty value is NULL, and nothing equals NULL. Test it with
IS NULL or IS NOT NULL. A patient still in a bed has no discharge_date.
- Ask what each row is.
hd_patients has one row per patient; hd_encounters one row per visit or stay. The data dictionary beside each table says so.
Patients still in a bed.