Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
RIGHT JOIN.docx59 KB RIGHT JOIN - Solution.docx
59.5 KB
Quick reference
RIGHT JOIN
Right Joins allow us to pull data from two tables when there is a match in at least the Right Table.
When to use
Use them when you know your data exists in at least the right table.
Instructions
SELECT [First Name], [Red Widget]
FROM [dbo].[Current_Customers]
RIGHT JOIN [dbo].[Orders] ON [Current_Customers].[Customer ID] = [Orders].[Customer ID]
This will display the last name and number of blue widgets purchased by each customer ID.
Similarly to LEFT JOIN, with RIGHT JOIN only one table needs to have the thing that you designate (e.g. Customer ID) in order to work. In this case, it is the table on the right that needs to have that thing in common. The table on the right is the second table that you list, which in this example is the Orders table.
This means if you have a customer who has a customer ID in the Current Customers table, but not the Orders table, they will not show up in your results at all, because they do not exist in the right table.
Hints & tips
- RIGHT JOINS work when the data exists in at least the right table.
Lesson notes are only available for subscribers.