codegurukool.com · Free coding tutorials & online compiler

Home › SQL Tutorial › SQL LEFT, RIGHT, FULL and SELF JOIN

SQL LEFT, RIGHT, FULL and SELF JOIN

Keep rows even when there is no match.

LEFT JOIN keeps every row of the left table and fills missing matches with NULL. RIGHT JOIN does the same for the right table, and FULL JOIN keeps both sides (not available in MySQL). A self join joins a table to itself using two aliases. This query finds customers with no orders.

Example code

SELECT c.name, o.amount
FROM Customers c
LEFT JOIN Orders o ON c.id = o.customer_id
WHERE o.id IS NULL;

Run this code in the online editor

← SQL INNER JOINSQL UNION and UNION ALL →