SQL RIGHT JOIN Keyword
The RIGHT JOIN command returns all rows from the right table and the matching rows from the left table. If there is no match, the result from the left table will show as NULL.
SQL RIGHT JOIN Syntax
SQL
x
1
SELECT column_names
2
FROM table1
3
RIGHT JOIN table2
4
ON table1.column_name = table2.column_name;
SQL RIGHT JOIN Doctors and Appointments Example
This query selects all doctors and any appointments they may have scheduled.
SQL
1
1
SELECT Appointments.appointment_id, Doctors.doctor_id, Doctors.first_name
2
FROM Appointments
3
RIGHT JOIN Doctors ON Appointments.doctor_id = Doctors.doctor_id
4
ORDER BY Appointments.appointment_id;
Note: This code does not work in the TechKubo playground. SQLite (and the TechKubo playground) does not support
RIGHT JOIN
. You can achieve similar results usingLEFT JOIN
by reversing the table order.