LEFT JOIN preserves all rows from the table written on the left, while RIGHT JOIN preserves all rows from the table written on the right.
Understanding table position helps prevent incorrect assumptions about which records will be preserved.
A RIGHT JOIN can usually be rewritten as a LEFT JOIN by reversing the table order.
SELECT
d.DepartmentName,
e.EmployeeName
FROM Departments d
LEFT JOIN Employees e
ON d.DepartmentID = e.DepartmentID;
These concepts are useful when analyzing missing relationships and designing queries across multiple business tables.
- LEFT JOIN preserves the left table.
- RIGHT JOIN preserves the right table.
- Table position determines which side is preserved.
- RIGHT JOIN can usually be rewritten as LEFT JOIN.
- LEFT JOIN is often preferred for readability.
What is the difference between LEFT JOIN and RIGHT JOIN?
LEFT JOIN preserves all rows from the left table, while RIGHT JOIN preserves all rows from the right table.
Can RIGHT JOIN be replaced with LEFT JOIN?
Yes. Reverse the table order and use LEFT JOIN to produce an equivalent relationship.