An INNER JOIN returns only the rows where there is a match in both tables based on the join condition. If a row in either table does not have a corresponding match, it will be excluded from the result.

SELECT * FROM TableA
INNER JOIN TableB
ON TableA.col_match = TableB.col_match

Note

Writing join on its own will usually be treated as an inner join in most SQL engines.

Example

Given two tables:

Customers

idnamecity
1AliceNew York
2BobChicago
3CharlieSan Diego

Orders

idcustomer_idproduct
11Laptop
21Keyboard
33Monitor

Using an INNER JOIN to retrieve customers who have placed orders:

SELECT Customers.name, Orders.product  
FROM Customers  
INNER JOIN Orders ON Customers.id = Orders.customer_id;

Result:

nameproduct
AliceLaptop
AliceKeyboard
CharlieMonitor

Key Differences from Other Joins:

  • Unlike a LEFT JOIN, which includes unmatched rows from the left table, an INNER JOIN only includes matches.
  • Unlike a RIGHT JOIN, which includes unmatched rows from the right table, an INNER JOIN only includes matches.
  • Unlike a FULL OUTER JOIN, which includes unmatched rows from both tables, an INNER JOIN filters them out.