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
SELECT column_names FROM table1 LEFT JOIN table2 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.
SELECT Patients.first_name, Appointments.appointment_id FROM Patients 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.
SELECT Appointments.appointment_id, Prescriptions.prescription_id FROM Appointments LEFT JOIN Prescriptions ON Appointments.appointment_id = Prescriptions.appointment_id;
