SQL intermediate join inner join three tables query

How to JOIN Three Tables in SQL

JOIN Three Tables is a SQL query that this query pulls from three tables — orders, customers, and products — joining them on their foreign key relationships to build a complete picture of each order.. Formula Genius generates and validates this formula automatically from a plain-English prompt.

Most real queries need data from 3+ tables. Here's the clean pattern for multi-table JOINs that actually performs well.

The Formula

Prompt

"Get order details with customer name and product name from three tables"

SQL
SELECT o.order_id, c.name AS customer, p.name AS product, o.quantity
FROM orders o
INNER JOIN customers c ON o.customer_id = c.id
INNER JOIN products p ON o.product_id = p.id
WHERE o.created_at >= '2026-01-01'
ORDER BY o.created_at DESC;

This query pulls from three tables — orders, customers, and products — joining them on their foreign key relationships to build a complete picture of each order.

Step-by-Step Breakdown

  1. FROM orders o — start with the orders table (aliased as 'o')
  2. INNER JOIN customers c ON o.customer_id = c.id — add customer names
  3. INNER JOIN products p ON o.product_id = p.id — add product names
  4. WHERE filters to orders from 2026 onward
  5. ORDER BY sorts newest orders first

Edge Cases & Warnings

  • INNER JOIN excludes orders with no matching customer or product
  • Use LEFT JOIN to include orders even without a matching record
  • Missing indexes on join columns can make this query very slow
  • NULL values in join columns are never matched by JOIN

Examples

Prompt

"3 tables: orders, customers, products"

SQL
Combined view with customer name + product name per order
Prompt

"Add LEFT JOIN for customers"

SQL
Includes orders even if customer was deleted

Frequently Asked Questions

How many tables can I JOIN?

Technically unlimited, but each JOIN adds performance cost. Most queries join 3-5 tables. If you need 10+, consider restructuring your data or using CTEs for clarity.

INNER JOIN vs LEFT JOIN — which should I use?

INNER JOIN: only show rows with matches in BOTH tables. LEFT JOIN: show all rows from the left table, even without matches. Use LEFT JOIN when data might be missing.

Can't find what you need?

Describe any formula in plain English and Formula Genius will generate, explain, and validate it — instantly.