SQL RIGHT JOIN
The SQL RIGHT JOIN returns all records from the right table and the matching records from the left. When no match exists in the left table, NULL appears for those columns.
Complete Python Course with Advance topics:-
SQL Tutorial:-
Syntax
SELECT Table1.column1, Table2.column2
FROM Table1
RIGHT JOIN Table2
ON Table1.common_column = Table2.common_column;
Example 1: Employees & Departments
SELECT e.EmpID, e.Emp_Name, e.Emp_Salary, d.Dept_Name
FROM Employees e
RIGHT JOIN Departments d ON e.EmpID = d.Emp_ID;
All departments appear; an IT department without an employee shows NULL for employee fields.
Example 2: Loans & Borrowers
SELECT l.LoanID, l.Branch, l.Amount, b.CustID, b.Cust_Name
FROM Loans l
RIGHT JOIN Borrowers b ON l.LoanID = b.LoanID;
All borrowers appear; a borrower with a loan ID not in Loans shows NULL for loan fields.
RIGHT JOIN vs LEFT JOIN
- RIGHT JOIN: Keeps every row from the RIGHT table.
- LEFT JOIN: Keeps every row from the LEFT table.
- You can convert a RIGHT JOIN to a LEFT JOIN by swapping the table order ÔÇö readability often favours LEFT JOIN.
When to Use RIGHT JOIN
- The right table is the “primary reference” you want to fully preserve.
- You want NULLs where left-table data is missing.
- You are appending optional data on the left to a complete list on the right.
Download New Real Time Projects:- Click here
Complete Advance AI topics:-
Conclusion
RIGHT JOIN guarantees every row from the right table appears, with NULLs filling unmatched columns from the left. It is perfect when the right table holds your primary list. For more SQL tutorials, stay tuned to .
sql right join vs left join
sql right outer join
right join example
sql joins
left join in sql
full join in sql
inner join in sql
sql right join w3schools