SyntaxStudy
Sign Up
MySQL Beginner 8 min read

INNER JOIN

INNER JOIN in MySQL

INNER JOIN returns only rows with matching values in both tables.

Syntax

SELECT columns
FROM table1
INNER JOIN table2 ON table1.key = table2.key;

Example

SELECT
    o.id AS order_id,
    u.username,
    u.email,
    o.amount,
    o.created_at
FROM orders o
INNER JOIN users u ON o.user_id = u.id
ORDER BY o.created_at DESC;

Multiple Joins

SELECT
    o.id,
    u.username,
    p.name AS product,
    oi.quantity,
    oi.price
FROM order_items oi
INNER JOIN orders o ON oi.order_id = o.id
INNER JOIN users u ON o.user_id = u.id
INNER JOIN products p ON oi.product_id = p.id;
Pro Tip

INNER JOIN is the most common join — it excludes rows that don't have matches in both tables.