How to Join Three Tables in SQL: A Beginner’s Guide
James Reed
Infrastructure Engineer · Leapcell

Key Takeaways
- SQL joins can combine three tables using chained JOIN statements.
- Identifying the correct columns is essential for successful multi-table joins.
- Using table aliases improves query readability.
When working with databases, you’ll often encounter situations where you need to retrieve data spread across multiple tables. SQL joins are powerful tools that help you combine data from two or more tables based on related columns. But what if you need to join three tables? In this article, we’ll explore how to join three tables in SQL, step by step, with clear examples.
Understanding SQL Joins
Before joining three tables, let's quickly review what a join is. An SQL join brings together records from two tables based on a related column between them, such as a foreign key.
The most commonly used joins are:
- INNER JOIN: Returns only matching rows from both tables.
- LEFT JOIN (or LEFT OUTER JOIN): Returns all rows from the left table and the matched rows from the right table; unmatched rows will have
NULL
values. - RIGHT JOIN (or RIGHT OUTER JOIN): Returns all rows from the right table and the matched rows from the left table.
Joining Three Tables: The Basics
You can join more than two tables in SQL by chaining multiple JOIN statements together. The key is to identify the columns that connect your tables.
Example Database Structure
Imagine we have the following three tables:
-
Customers
customer_id
customer_name
-
Orders
order_id
customer_id
order_date
-
Products
product_id
product_name
-
OrderDetails
order_id
product_id
quantity
Suppose we want to find the customer name, the product name, and the quantity ordered for each order.
SQL Query to Join Three Tables
To do this, we can join the tables as follows:
SELECT Customers.customer_name, Products.product_name, OrderDetails.quantity FROM Customers INNER JOIN Orders ON Customers.customer_id = Orders.customer_id INNER JOIN OrderDetails ON Orders.order_id = OrderDetails.order_id INNER JOIN Products ON OrderDetails.product_id = Products.product_id;
How Does This Work?
-
Customers INNER JOIN Orders Joins customers with their orders.
-
Orders INNER JOIN OrderDetails Joins orders with the specific details (which products were ordered).
-
OrderDetails INNER JOIN Products Joins order details with the product information.
Each join connects one more table using a relevant column (usually a foreign key). This allows you to access fields from all the joined tables in your SELECT
statement.
Using Aliases for Clarity
To make queries more readable, you can use table aliases:
SELECT c.customer_name, p.product_name, od.quantity FROM Customers c INNER JOIN Orders o ON c.customer_id = o.customer_id INNER JOIN OrderDetails od ON o.order_id = od.order_id INNER JOIN Products p ON od.product_id = p.product_id;
Other Types of Joins
While the example above uses INNER JOIN
, you can use LEFT JOIN
or RIGHT JOIN
as needed. For example, if you want to include customers who haven’t placed any orders, you would use a LEFT JOIN
between Customers and Orders.
SELECT c.customer_name, p.product_name, od.quantity FROM Customers c LEFT JOIN Orders o ON c.customer_id = o.customer_id LEFT JOIN OrderDetails od ON o.order_id = od.order_id LEFT JOIN Products p ON od.product_id = p.product_id;
Conclusion
Joining three tables in SQL is straightforward once you understand the relationships between your tables. You simply chain multiple JOIN statements together, always joining on the columns that relate the tables. By mastering multi-table joins, you’ll unlock much more powerful queries and insights from your data.
FAQs
Chain multiple JOIN statements using related columns.
Yes, you can use INNER JOIN, LEFT JOIN, or RIGHT JOIN as needed.
Aliases make complex queries easier to read.
We are Leapcell, your top choice for hosting backend projects.
Leapcell is the Next-Gen Serverless Platform for Web Hosting, Async Tasks, and Redis:
Multi-Language Support
- Develop with Node.js, Python, Go, or Rust.
Deploy unlimited projects for free
- pay only for usage — no requests, no charges.
Unbeatable Cost Efficiency
- Pay-as-you-go with no idle charges.
- Example: $25 supports 6.94M requests at a 60ms average response time.
Streamlined Developer Experience
- Intuitive UI for effortless setup.
- Fully automated CI/CD pipelines and GitOps integration.
- Real-time metrics and logging for actionable insights.
Effortless Scalability and High Performance
- Auto-scaling to handle high concurrency with ease.
- Zero operational overhead — just focus on building.
Explore more in the Documentation!
Follow us on X: @LeapcellHQ