Key Concepts

Review core concepts you need to learn to master this subject

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
  1. 1
    In 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 …
  2. 2
    Let’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…
  3. 3
    Combining 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…
  4. 4
    Let’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…
  5. 5
    What 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…
  6. 6
    Let’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…
  7. 7
    So 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…
  8. 8
    Sometimes we just want to stack one dataset on top of the other. Well, the UNION operator allows us to do that. Suppose we have two tables and they have the same columns. table1: | pokemon | ty…
  9. 9
    Often times, we want to combine two tables, but one of the tables is the result of another calculation. Let’s return to our magazine order example. Our marketing department might want to know a b…
  10. 10
    In this lesson, we learned about relationships between tables in relational databases and how to query information from multiple tables using SQL. Let’s summarize what we’ve learned so far: - JOI…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo