RIGHT JOIN

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.

Tutorials dojo strip

SQL RIGHT JOIN Syntax

SELECT column_names
FROM table1
RIGHT JOIN table2
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.

SELECT Appointments.appointment_id, Doctors.doctor_id, Doctors.first_name
FROM Appointments
RIGHT JOIN Doctors ON Appointments.doctor_id = Doctors.doctor_id
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 using LEFT JOIN by reversing the table order.

SQL RIGHT JOIN Labs

Tutorials dojo strip
Scroll to Top