A Full Join or Full Outer Join returns all records when there is a match in either left or right table records. If there is no match, the result is NULL on the side that does not have match.
SQL Full Join Syntax
SQL
x
1
SELECT column1, column2, ...
2
FROM table1
3
FULL JOIN table2
4
ON table1.column_name = table2.column_name;
SQL Full Join Doctors and Appointments Example
This query returns all doctors and their corresponding appointments, including those doctors without appointments and appointments without corresponding doctors.
SQL
1
1
SELECT d.first_name, d.last_name, a.appointment_date
2
FROM Doctors d
3
FULL JOIN Appointments a ON d.doctor_id = a.doctor_id;
SQL Full Join Patients and Appointments Example
This query retrieves all patients along with their appointments. If a patients does not have an appointment, the appointment date will show as NULL.
SQL
1
1
SELECT p.first_name, a.appointment_date
2
FROM Patients p
3
FULL JOIN Appointments a ON p.patient_id = a.patient_id;