Course Content
Intermediate SQL
Intermediate SQL
LEFT, RIGHT and INNER JOINs
Great job! The online store has placed an order with a supplier for products they were running low on in stock, so they won't need us until the shipment arrives.
This is a great opportunity to learn something new! Throughout the past 4 chapters, you've been using the standard JOIN
without knowing that there are other ways to join tables.
There are 4 main types of table joins:
INNER JOIN
: Returns only the rows that have matching values in both tables; (This join has the same functionality as the standard JOIN you've been using so far)LEFT JOIN
: Returns all rows from the left table and the matching rows from the right table. If there are no matches, it returnsNULL
for the right table;RIGHT JOIN
: Returns all rows from the right table and the matching rows from the left table. If there are no matches, it returnsNULL
for the left table;FULL JOIN
: Returns all rows when there is a match in one of the tables. If there are no matches, it returnsNULL
for the missing values in the other table.
Before we start working with these types of joins, let's take a look at the new two tables we'll be working with. These tables contain information about courses as well as students enrolled in these courses.
courses
:
enrollments
:
The syntax for using these types of joins is actually simple. Instead of the familiar JOIN
or INNER JOIN
, just specify LEFT JOIN
or any other type of JOIN
.
In this case, the syntax will look like this:
From this syntax, it's clear which table will be the left table and which will be the right table.
Let's move on to the task!
Task
Write a query to retrieve a list of all courses and the students enrolled, including courses with no registered students.
You need to fetch the following columns in this order:
Use the appropriate type of JOIN
to solve this task!
Task
Write a query to retrieve a list of all courses and the students enrolled, including courses with no registered students.
You need to fetch the following columns in this order:
Use the appropriate type of JOIN
to solve this task!
Everything was clear?
LEFT, RIGHT and INNER JOINs
Great job! The online store has placed an order with a supplier for products they were running low on in stock, so they won't need us until the shipment arrives.
This is a great opportunity to learn something new! Throughout the past 4 chapters, you've been using the standard JOIN
without knowing that there are other ways to join tables.
There are 4 main types of table joins:
INNER JOIN
: Returns only the rows that have matching values in both tables; (This join has the same functionality as the standard JOIN you've been using so far)LEFT JOIN
: Returns all rows from the left table and the matching rows from the right table. If there are no matches, it returnsNULL
for the right table;RIGHT JOIN
: Returns all rows from the right table and the matching rows from the left table. If there are no matches, it returnsNULL
for the left table;FULL JOIN
: Returns all rows when there is a match in one of the tables. If there are no matches, it returnsNULL
for the missing values in the other table.
Before we start working with these types of joins, let's take a look at the new two tables we'll be working with. These tables contain information about courses as well as students enrolled in these courses.
courses
:
enrollments
:
The syntax for using these types of joins is actually simple. Instead of the familiar JOIN
or INNER JOIN
, just specify LEFT JOIN
or any other type of JOIN
.
In this case, the syntax will look like this:
From this syntax, it's clear which table will be the left table and which will be the right table.
Let's move on to the task!
Task
Write a query to retrieve a list of all courses and the students enrolled, including courses with no registered students.
You need to fetch the following columns in this order:
Use the appropriate type of JOIN
to solve this task!
Task
Write a query to retrieve a list of all courses and the students enrolled, including courses with no registered students.
You need to fetch the following columns in this order:
Use the appropriate type of JOIN
to solve this task!
Everything was clear?
LEFT, RIGHT and INNER JOINs
Great job! The online store has placed an order with a supplier for products they were running low on in stock, so they won't need us until the shipment arrives.
This is a great opportunity to learn something new! Throughout the past 4 chapters, you've been using the standard JOIN
without knowing that there are other ways to join tables.
There are 4 main types of table joins:
INNER JOIN
: Returns only the rows that have matching values in both tables; (This join has the same functionality as the standard JOIN you've been using so far)LEFT JOIN
: Returns all rows from the left table and the matching rows from the right table. If there are no matches, it returnsNULL
for the right table;RIGHT JOIN
: Returns all rows from the right table and the matching rows from the left table. If there are no matches, it returnsNULL
for the left table;FULL JOIN
: Returns all rows when there is a match in one of the tables. If there are no matches, it returnsNULL
for the missing values in the other table.
Before we start working with these types of joins, let's take a look at the new two tables we'll be working with. These tables contain information about courses as well as students enrolled in these courses.
courses
:
enrollments
:
The syntax for using these types of joins is actually simple. Instead of the familiar JOIN
or INNER JOIN
, just specify LEFT JOIN
or any other type of JOIN
.
In this case, the syntax will look like this:
From this syntax, it's clear which table will be the left table and which will be the right table.
Let's move on to the task!
Task
Write a query to retrieve a list of all courses and the students enrolled, including courses with no registered students.
You need to fetch the following columns in this order:
Use the appropriate type of JOIN
to solve this task!
Task
Write a query to retrieve a list of all courses and the students enrolled, including courses with no registered students.
You need to fetch the following columns in this order:
Use the appropriate type of JOIN
to solve this task!
Everything was clear?
Great job! The online store has placed an order with a supplier for products they were running low on in stock, so they won't need us until the shipment arrives.
This is a great opportunity to learn something new! Throughout the past 4 chapters, you've been using the standard JOIN
without knowing that there are other ways to join tables.
There are 4 main types of table joins:
INNER JOIN
: Returns only the rows that have matching values in both tables; (This join has the same functionality as the standard JOIN you've been using so far)LEFT JOIN
: Returns all rows from the left table and the matching rows from the right table. If there are no matches, it returnsNULL
for the right table;RIGHT JOIN
: Returns all rows from the right table and the matching rows from the left table. If there are no matches, it returnsNULL
for the left table;FULL JOIN
: Returns all rows when there is a match in one of the tables. If there are no matches, it returnsNULL
for the missing values in the other table.
Before we start working with these types of joins, let's take a look at the new two tables we'll be working with. These tables contain information about courses as well as students enrolled in these courses.
courses
:
enrollments
:
The syntax for using these types of joins is actually simple. Instead of the familiar JOIN
or INNER JOIN
, just specify LEFT JOIN
or any other type of JOIN
.
In this case, the syntax will look like this:
From this syntax, it's clear which table will be the left table and which will be the right table.
Let's move on to the task!
Task
Write a query to retrieve a list of all courses and the students enrolled, including courses with no registered students.
You need to fetch the following columns in this order:
Use the appropriate type of JOIN
to solve this task!