INNER JOIN: Returns only the rows where there is a match in both tables
SELECT customers.name, orders.order_number
FROM customers
INNERJOIN orders
ON customers.id = orders.customer_id;
LEFT JOIN (or LEFT OUTER JOIN): Returns all the rows from the left table and the matching rows from the right table. If there is no match, NULL values will be returned for the columns from the right table.
SELECT customers.name, orders.order_number
FROM customers
LEFTJOIN orders
ON customers.id = orders.customer_id;
RIGHT JOIN (or RIGHT OUTER JOIN): Returns all the rows from the right table and the matching rows from the left table. If there is no match, NULL values will be returned for the columns from the left table.
SELECT customers.name, orders.order_number
FROM customers
RIGHTJOIN orders
ON customers.id = orders.customer_id;
FULL OUTER JOIN: Returns all the rows from both tables, including the matching and non-matching rows. If there is no match, NULL values will be returned for the missing columns.
SELECT customers.name, orders.order_number
FROM customers
FULLOUTERJOIN orders
ON customers.id = orders.customer_id;