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
ONstates the relationship between the two tables.- Table aliases keep long column references short.
- Rows without a partner are dropped from the result.
Keywords and builtins used here
ASBYDESCFROMINNERJOINONORDERSELECTWHEREc
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.
Step 1 of 9 in Joins, step 9 of 22 in Joins & aggregation.