RIGHT JOIN
This type of join is used when you want to select records that are available in the second table and matching records in the first one. This can be visualized with the following Venn diagram:
As we can see, the RIGHT JOIN
represents the highlighted section, that is, TABLE B, and the intersected section of TABLE A. Let's look at the syntax for the RIGHT JOIN
:
SELECT [Column List] FROM [Table 1] RIGHT OUTER JOIN [Table 2] ON [Table 1 Column Name] = [Table 2 Column Name] WHERE [Condition]
The syntax can also be written as follows:
SELECT [Column List] FROM [Table 1] RIGHT JOIN [Table 2] ON [Table 1 Column Name] = [Table 2 Column Name] WHERE [Condition]
Note
Writing OUTER
in the query is optional.
Exercise 6.02: Implementing RIGHT JOIN
The store wants the list of customers, along with their orders, and also wants to include customers...