When working with relational databases, it's often necessary to combine data from multiple tables. SQL provides the JOIN operation to link tables together based on a related column between them. Here, we'll discuss how to perform a JOIN operation with three tables in SQL.

Before we dive into the three-table JOIN, let's refresh our understanding of the JOIN concept with a simple two-table example. Consider two tables, 'Orders' and 'Customers', with a common column 'CustomerID'.

Understanding SQL JOINs
In this example, we'll use an INNER JOIN to combine rows from both tables where there's a match in 'CustomerID'.

```sql SELECT Orders.OrderID, Customers.CustomerName FROM Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID; ```
The result will be a table with 'OrderID' and 'CustomerName' columns, showing orders along with the customer names.
Types of JOINs

There are several types of JOINs in SQL: INNER JOIN, LEFT (OUTER) JOIN, RIGHT (OUTER) JOIN, and FULL (OUTER) JOIN. Familiarize yourself with each to choose the right one for your use case.
Joining Three Tables
Now, let's consider three tables: 'Orders', 'Customers', and 'Employees'. The 'Employees' table has a 'ManagerID' field that references 'CustomerID' in the 'Customers' table. We want to see orders along with the customer's name and their manager's name.

Three-Table JOIN Example
To achieve this, we'll perform a three-table JOIN using INNER JOINs.
```sql SELECT Orders.OrderID, Customers.CustomerName, Employees.EmployeeName FROM Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID INNER JOIN Employees ON Customers.ManagerID = Employees.EmployeeID; ```
The result will now include the 'OrderID', 'CustomerName', and 'EmployeeName' (manager's name) columns.

Using LEFT JOINs in Three-Table Queries
Sometimes, you might want to include all records from one table and matching records from other tables. In such cases, use a LEFT JOIN. Here's how you can modify the previous query to include all customers, even if they don't have a related order or manager:




















```sql SELECT Orders.OrderID, Customers.CustomerName, Employees.EmployeeName FROM Customers LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID LEFT JOIN Employees ON Customers.ManagerID = Employees.EmployeeID; ```
With this, you now have a solid foundation to work with three-table JOINs in SQL, allowing you to query and analyze data from multiple tables more efficiently.