SQL INNER JOIN

The SQL INNER JOIN Keyword

The INNER JOIN keyword selects records that have matching values in both tables. It is the most common type of join.

!INNER JOIN Diagram


INNER JOIN Syntax

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;

Note: JOIN is the same as INNER JOIN. You can use either.


Demo Database

We will use the Customers and Orders tables.

Customers Table:

CustomerID CustomerName
1 Alfreds Futterkiste
2 Ana Trujillo Emparedados
3 Antonio Moreno Taquería

Orders Table:

OrderID CustomerID OrderDate
10308 2 1996-09-18
10309 3 1996-09-19
10310 1 1996-09-20

INNER JOIN Example

The following SQL statement will select all orders with customer information. It matches rows from Customers and Orders where the CustomerID is the same in both tables.

INNER JOIN Example

SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;

The result set would look like this:

OrderID CustomerName
10310 Alfreds Futterkiste
10308 Ana Trujillo Emparedados
10309 Antonio Moreno Taquería

Only customers who have placed an order will appear in the result.