LEFT and RIGHT JOIN

LEFT JOIN returns all rows from the left table and matched rows from the right.

SELECT customers.name, orders.id
FROM customers
LEFT JOIN orders
ON customers.id = orders.customer_id;

RIGHT JOIN is the opposite — all rows from the right table, matched ones from the left.

SELECT orders.id, customers.name
FROM orders
RIGHT JOIN customers
ON orders.customer_id = customers.id;
← PrevNext →