INNER JOIN in SQL

Level 390 keystrokes

INNER JOIN returns rows that have matching values in both tables.

SQL code

-- Take the name from users and the total from orders
1SELECT
2 users.name,
3 orders.total
-- users is the left (first) table of the join
4FROM
5 users
-- Pair each user with each of their orders, matched on users.id = orders.user_id
-- Users without orders are left out; a user with 2 orders appears twice (Alice)
6INNER JOIN
7 orders ON users.id = orders.user_id;

Output

+-------+-------+
| name  | total |
+-------+-------+
| Alice | 99.50 |
| Alice | 45.00 |
| Bob   | 75.25 |
+-------+-------+
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.

  • .× 4
  • _× 1
  • ,× 1
  • ;× 1
  • =× 1

More SQL examples at level 3

← SQL typing practice