Course contentsShow
← Computer Science
Lesson 1576 of 2,87236. Database FundamentalsFree lesson

What is a Join?

Understanding how joins combine rows from two or more tables based on related columns.

What is a Join?

You'll learn: How to combine data from multiple tables using joins to create meaningful relationships between your data.

The Core Idea

A join is an SQL operation that combines rows from two or more tables based on a related column between them. Think of it like matching puzzle pieces: you have information split across different tables, and joins let you connect those pieces using common values.

Why Joins Matter

Imagine you have two tables:

  • Customers table: customer_id, name, email
  • Orders table: order_id, customer_id, product, price

The customer_id appears in both tables. A join lets you answer questions like "Show me all orders along with the customer names who placed them" — something neither table can answer alone.

The Matching Process

When you perform a join, the database compares each row in one table with rows in another table. When it finds matching values in the specified columns (like customer_id in both tables), it combines those rows into a single result row.

For example, if customer "Alice" has customer_id = 5, and the Orders table has three rows where customer_id = 5, the join would produce three combined rows showing Alice's name alongside each of her three orders.

The Relationship

Joins work because of foreign keys — those references between tables you learned earlier. The foreign key in one table points to the primary key in another, creating the relationship that joins exploit.

Key Takeaway: Joins combine rows from multiple tables by matching values in related columns, allowing you to query interconnected data as if it were in a single table.