SQLIntermediate#joins

Explain all types of JOIN with an example.

INNER JOIN returns only matching rows. LEFT/RIGHT JOIN returns every row of one side plus matches (NULLs otherwise). FULL OUTER JOIN returns both sides. CROSS JOIN returns the Cartesian product. SELF JOIN joins a table to itself.

Example
SELECT e.name, d.name
FROM employees e
LEFT JOIN departments d ON d.id = e.dept_id;
-- employees without a department still appear, d.name IS NULL

Related Questions

1
SQLIntermediate#joins

What is a SELF JOIN?

Open
2
SQLIntermediate#aggregates

Difference between WHERE and HAVING?

Open
3
SQLIntermediate#queries

What is the logical order of execution of a SELECT query?

Open