From the course: SQL Essential Training
The RIGHT JOIN
- [Instructor] Now before getting into our right outer join, I wanted to remind you about something we mentioned in the beginning of the course with regard to relational database management systems. If you recall, we did mention there are various types of relational database management systems, such as the one we're using for this course, SQL Light. But there are others like Microsoft SQL Server and Oracle. And we mentioned that there is about a 5% difference with regard to the syntax that you would write in one RDBMS versus another. Now, I'm calling this out before getting into the right outer join, because right outer joins are not supported in SQL Light. But since right joins are still very popular in other relational database management systems I think it's appropriate to include it in our discussion here. Now, the right outer join returns the entire right table as well as matching information from the left table. The right join is a mirror image of the left join, and functions in a very similar way. Now, similar to what occurred in the left join, the right join takes all fields from the right table, in this case the customer's table, and matches that data with any corresponding data from the invoice table or the left table. Now again, if we look at our simplified invoice and customer table, since customer six does not exist in the customer table, this record is simply ignored. The SQL statement required to create a right join is not surprisingly, similar to the other two joins we've shown thus far. If we take a look at the syntax here, all we have done to create a right join again is replace left outer join, as we did previously, with right outer join. Now, this particular join returned the most records out of the three joins we've demonstrated thus far. Customer number one and customer number five did not have corresponding data in the invoice table. So null values were assigned to those records. Two records from the invoice table corresponded to customer number two, so to join resulted in data from customer two being listed twice. Now right joins are used less frequently than left joins, and since SQL Light does not recognize the right join, it is a best practice to reverse the order of the tables in your query which would actually give you the same result. We'll demonstrate this a little later. Now, so far we've taken a look at inner join, left join, and right join. And in all of our examples thus far, we've been joining just two tables. Well, it is possible to perform joins on more than two tables, so let's take a look at how we would generate the sequel syntax to do this.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
- Joins explained1m 41s
- How tables share a relationship, part 15m 53s
- How tables share a relationship, part 24m 22s
- Simplifying JOINs5m 41s
- Types of JOINs2m 55s
- The INNER JOIN2m 20s
- The LEFT JOIN2m 59s
- The RIGHT JOIN3m 29s
- Tables and Entity Relationship diagrams4m 41s
- Joining many tables5m 45s
- Solution: Analyzing customer support interactions3m 3s
-
-
-
-
-
-
-
-