MySQL SQL

MySQL RIGHT JOIN

Keep every row from the right table.

SELECT p.name, c.name AS category
FROM products p
RIGHT JOIN categories c ON c.id = p.category_id;

Categories without products remain. Rewriting the query with a LEFT JOIN is often easier to read.