# Self Joins & Joining 3+ Tables — MySQL

Source: https://www.geekswithgeeks.com/en/mysql/sql-self-multi-join

> Join a table to itself, and chain several joins together.

## Self join

A **self join** joins a table to itself — useful for hierarchies, like an employee and their manager in the same table.

```sql
SELECT e.name AS employee, m.name AS manager
FROM employees e
LEFT JOIN employees m ON e.manager_id = m.id;
```

## Joining three tables

Chain multiple `JOIN`s to pull related data from several tables in one query.

```sql
SELECT c.name, o.id AS order_id, p.title, oi.quantity
FROM customers c
JOIN orders o ON o.customer_id = c.id
JOIN order_items oi ON oi.order_id = o.id
JOIN products p ON p.id = oi.product_id;
```
