Multiple Tables
Expand your SQL skills by creating and manipulating databases with multiple related tables
StartKey Concepts
Review core concepts you need to learn to master this subject
Outer Join
Outer Join
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
An outer join will combine rows from different tables even if the join condition is not met. In a LEFT JOIN
, every row in the left table is returned in the result set, and if the join condition is not met, then NULL
values are used to fill in the columns from the right table.
Multiple Tables
Lesson 1 of 1
- 1In order to efficiently store data, we often spread related information across multiple tables. For instance, imagine that we’re running a magazine company where users can have different types of …
- 2Let’s return to our magazine company. Suppose we have the three tables described in the previous exercise – shown in the browser on the right (we are going to try something new!): - orders - subsc…
- 3Combining tables manually is time-consuming. Luckily, SQL gives us an easy sequence for this: it’s called a JOIN. If we want to combine orders and customers, we would type: SELECT * FROM orders JO…
- 4Let’s revisit how we joined orders and customers. For every possible value of customer_id in orders, there was a corresponding row of customers with the same customer_id. What if that wasn’t true…
- 5What if we want to combine two tables and keep some of the un-matched rows? SQL lets us do this through a command called LEFT JOIN. A left join will keep all rows from the first table, regardles…
- 6Let’s return to our example of the magazine subscriptions. Recall that we had three tables: orders, subscriptions, and customers. Each of these tables has a column that uniquely identifies each ro…
- 7So far, we’ve focused on matching rows that have some information in common. Sometimes, we just want to combine all rows of one table with all rows of another table. For instance, if we had a tab…
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory