INNER JOIN in SQL

Level 4115 keystrokes

INNER JOIN returns only rows that have a match in both tables; WHERE then filters the joined rows.

SQL code

-- Take the user's name and the order total from the two tables
1SELECT
2 users.name,
3 orders.total
4FROM
5 users
-- Join each user to their orders where users.id = orders.user_id
-- Users without orders do not appear at all
6INNER JOIN
7 orders ON users.id = orders.user_id
-- Keep only orders over 100; Alice appears twice because she has two of them
8WHERE
9 orders.total > 100;

Output

+-------+--------+
| name  | total  |
+-------+--------+
| Alice | 150.00 |
| Bob   | 250.00 |
| Alice | 175.00 |
+-------+--------+
3 rows in set
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this SQL code and how often they appear.

  • .× 5
  • _× 1
  • ,× 1
  • ;× 1
  • =× 1
  • >× 1

More SQL examples at level 4

← SQL typing practice