typestar

INNER JOIN in SQL

An inner join keeps only the rows that match on both sides.

SELECT
    o.id,
    o.total,
    c.name AS customer
FROM orders AS o
INNER JOIN customers AS c
    ON c.id = o.customer_id
WHERE o.status = 'paid'
ORDER BY o.total DESC;

How it works

  1. ON states the relationship between the two tables.
  2. Table aliases keep long column references short.
  3. Rows without a partner are dropped from the result.

Keywords and builtins used here

The run, in numbers

Lines
9
Characters to type
154
Tokens
44
Three-star pace
85 tpm

At the three-star pace of 85 tokens a minute, this run takes about 31 seconds.

Type this snippet

Step 1 of 9 in Joins, step 9 of 22 in Joins & aggregation.

← Previous Next →