SQL Inner Join
SQL INNER JOIN
INNER JOIN returns only the rows where there is a match in both joined tables. It is the most commonly used type of JOIN.
Basic Syntax
SELECT columns FROM table1 INNER JOIN table2 ON table1.column = table2.column;
Example: Customers and Orders
SELECT c.name, o.order_date FROM customers AS c INNER JOIN orders AS o ON c.id = o.customer_id;
This query returns only customers who have placed at least one order.
How INNER JOIN Works
Think of INNER JOIN as the intersection of two tables. Only matching rows are included in the result.
Primary Key and Foreign Key
INNER JOIN commonly connects a primary key in one table with a foreign key in another.
- customers.id (Primary Key)
- orders.customer_id (Foreign Key)
INNER JOIN with WHERE
You can filter results after joining tables.
SELECT c.name, o.order_date FROM customers AS c INNER JOIN orders AS o ON c.id = o.customer_id WHERE o.order_date > '2026-01-01';
Joining More Than Two Tables
You can chain multiple INNER JOINs.
SELECT c.name, o.order_date, p.name AS product_name FROM customers AS c INNER JOIN orders AS o ON c.id = o.customer_id INNER JOIN products AS p ON o.product_id = p.id;
NULL Behavior
Rows with NULL values in the join column will not match and will not appear in the result.
Common Mistakes
- Forgetting the ON condition
- Joining on the wrong column
- Creating unintended duplicates due to one-to-many relationships
Performance Note
Indexes on join columns (especially foreign keys) significantly improve performance for INNER JOIN queries.
Next Step
Continue with SQL LEFT JOIN to learn how to return all rows from the left table even if there is no match.