1. Explain the difference between INNER JOIN, LEFT JOIN and FULL OUTER JOIN with a simple example.
A strong answer covers:
- INNER JOIN returns only rows that match in both tables
- LEFT JOIN returns all rows from the left table plus matches, NULL where no match
- FULL OUTER JOIN returns all rows from both tables
- Gives a concrete example such as customers and orders
Show model answer
Take a customers table and an orders table joined on customer_id. An INNER JOIN returns only customers who have at least one order, because it keeps rows that match on both sides. A LEFT JOIN from customers to orders returns every customer; for those with no orders, the order columns are NULL. This is what I use when I need "all customers with their order count, including zero". A FULL OUTER JOIN returns all rows from both tables: matched pairs, customers with no orders, and orders with no valid customer. That last one is useful for data quality checks, for example finding orphan orders. I also watch out for one-to-many joins, because joining customers to orders repeats the customer row for each order, which can inflate totals if I sum customer-level values.