Outer joins allow us to keep all rows from one table and fill in NULLs for missing matches in the other table. Inner joins only keep rows with matches in both tables.
Employees:
id | name
1 | Alice
2 | Bob
3 | Carol
Departments:
id | dept_name
1 | Sales
3 | HR
What is the result of this query?
SELECT Employees.name, Departments.dept_name
FROM Employees LEFT OUTER JOIN Departments ON Employees.id = Departments.id;
SELECT Employees.name, Departments.dept_name FROM Employees LEFT OUTER JOIN Departments ON Employees.id = Departments.id;
The LEFT OUTER JOIN returns all employees. For Bob, there is no matching department, so dept_name is NULL.
The correct syntax is 'FULL OUTER JOIN' with ON clause specifying the join condition. Other options have wrong keyword order or missing ON.
LEFT OUTER JOIN from Customers to Orders ensures all customers appear. Indexing Orders.customer_id speeds up matching orders lookup.
Products(id, name)
Sales(product_id, quantity)
Query:
SELECT Products.name, Sales.quantity
FROM Products LEFT OUTER JOIN Sales ON Products.id = Sales.product_id
WHERE Sales.quantity > 10;
Why might this query return fewer rows than the total number of products?
The WHERE clause filters after the join, so rows with no matching Sales (NULL quantity) are excluded. To keep all products, the condition should be in the JOIN or use IS NULL checks.
