SQL LEFT JOIN Keyword
The LEFT JOIN command is used to return all rows from the left table, and the matched rows from the right table. If there is no match, the result is NULL from the right side.
SQL LEFT JOIN Syntax
SQL
x
1
SELECT column_names
2
FROM table1
3
LEFT JOIN table2
4
ON table1.column_name = table2.column_name;
SQL LEFT JOIN Patients and Appointments Example
This query returns all patients, including those who may not have any appointments. If no match is found in the Appointments table, the related columns return NULL.
SQL
1
1
SELECT Patients.first_name, Appointments.appointment_id
2
FROM Patients
3
LEFT JOIN Appointments ON Patients.patient_id = Appointments.patient_id;

SQL LEFT JOIN Prescriptions and Appointments Example
This query shows all appointments and their corresponding prescriptions (if any). Appointments without a prescription will still be shown.
SQL
1
1
SELECT Appointments.appointment_id, Prescriptions.prescription_id
2
FROM Appointments
3
LEFT JOIN Prescriptions ON Appointments.appointment_id = Prescriptions.appointment_id;
