capypad
0 day streak
sql / beginner
Snippet

Joining Tables with INNER JOIN

INNER JOIN combines rows from two tables whenever there is a matching value in a common column. This allows you to retrieve data distributed across multiple tables in a single result set.

snippet.sql
sql
1
2
3
SELECT orders.order_id, customers.name
FROM orders
INNER JOIN customers ON orders.customer_id = customers.id;
Breakdown
1
SELECT orders.order_id, customers.name
Selects specific columns from both the 'orders' and 'customers' tables.
2
INNER JOIN customers
Identifies the second table to be linked to the primary table.
3
ON orders.customer_id = customers.id
Specifies the condition for the match, usually linking a foreign key to a primary key.