A JOIN combines rows from two or more tables using a related column, usually an id.
In the sample database, Orders.CustomerID refers to Customers.CustomerID.
Types of joins
INNER JOIN: only rows with a match in both tables.
LEFT JOIN: all rows from the left table, plus matches from the right.
RIGHT JOIN: all rows from the right table, plus matches from the left.
FULL JOIN: all rows from both tables.
💡 Key Takeaways: SQL Joins
Mastering SQL Joins helps you write clean and reliable SQL code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
SQL Joins Code Example
SQL
SELECT o.OrderID, c.CustomerName, o.OrderDate, o.Status
FROM Orders AS o
INNER JOIN Customers AS c ON o.CustomerID = c.CustomerID
ORDER BY o.OrderDate;
Free sign-in required · Google login available
SQL Joins Practice Exercises
Check what you learned in “SQL Joins”.
/ 3 solved
Fill in the blank
Join orders to customers.
SELECT * FROM Orders Customers ON Orders.CustomerID = Customers.CustomerID;
✓ Correct!Not quite. Try again.
Multiple choice
What does a JOIN do?
✓ Correct!Not quite. Try again.
Code challenge
Select OrderID and CustomerName for every order that has a matching customer, sorted by OrderID.
Write the code in the live editor. Your answer is checked automatically.