Skip to content

JOIN

In one line

A JOIN combines rows from two or more tables based on a condition — usually matching a foreign key to a primary key.

In simple words

A JOIN combines data from two tables into a single result set. The most common pattern is matching a foreign key in one table to the primary key in another — for example, joining orders to users on orders.user_id = users.id to see who placed each order.

There are several types of joins:

  • INNER JOIN: only rows that match in both tables.
  • LEFT JOIN: all rows from the left table, plus matches from the right (NULL if no match).
  • RIGHT JOIN: all rows from the right table, plus matches from the left.
  • FULL OUTER JOIN: all rows from both tables, matched where possible.

Joins are powerful but can be expensive on large tables. Always join on indexed columns when possible.

Example

sql
-- Find each order with the user's name
SELECT orders.id, users.name, orders.total
FROM orders
INNER JOIN users ON orders.user_id = users.id;

The INNER JOIN matches each order to its user, combining columns from both tables.

Related terms

Related Resources

Related Lessons

  • Joins

    Learn how to combine data from multiple tables.

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary