RIGHT JOIN

RIGHT JOIN (also called RIGHT OUTER JOIN) is used to retrieve all records from the right table, and the matched records from the left table.

If there is no match found in the left table, the result will still include the right tableโ€™s row, with NULL in the columns from the left table.

๐Ÿ“Œ Syntax:

SELECT table1.column_name, table2.column_name
FROM table1
RIGHT JOIN table2
ON table1.common_column = table2.common_column;

๐Ÿ“˜ Example:

Suppose you have two tables โ€” students and fees. You want to show all fee records, even if the student info is missing.

SELECT students.student_name, fees.total_fees
FROM students
RIGHT JOIN fees
ON students.student_id = fees.student_id;

Query

    SELECT 
    students.student_id,
    students.student_name,
    students.student_course,
    fees.total_fees,
    fees.paid_fees,
    fees.pending_fees,
    fees.status
    FROM students
    RIGHT JOIN fees 
    ON students.student_id = fees.student_id;

Out Put