LearnSQLSQL JOINs
RELATIONSHIPS

SQL JOINs

Combine related data from two tables using matching keys.

After this lessonUse INNER JOIN and understand when LEFT JOIN is safer.

How it works

JOINs let you connect normalized tables without copying data into one giant dataset. The ON condition defines how rows relate.

INNER JOIN keeps only matches. LEFT JOIN keeps every row from the left table and adds matching right-side data when available, which is useful for finding missing master data.

REAL WORK

Join a production-order table to material master data, or transaction records to employee/operator names.

SYNTAX

The pattern

SELECT a.column, b.column
FROM TableA a
INNER JOIN TableB b ON a.Key = b.Key;

Example

SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
TRY IT

Run the example

Edit the query and run it against the built-in demo tables. Nothing is sent to a server.

SQL playground

The learning runner supports SELECT, WHERE, LIKE, IN, BETWEEN, GROUP BY, HAVING, JOIN, aggregates, ORDER BY and LIMIT. Advanced lessons explain additional production SQL concepts even when the mini runner does not execute that syntax.

QUICK CHECK

Which join keeps every row from the left table?

Progress is stored only in this browser. No account required.