7 hours 36 minutes
Okay. Welcome back to Montel. To databases. This is lesson for sequel joints and currently were in sub lesson 4.5, the right outer joint, which is the inverse of the left outer joint.
We're going to return all the data they exist and be with the related data exists in a
and the vin diagram for that looks like this. We get everything back from table B and we get to related data back from table, eh?
Let's go ahead and get started with that, then. And we're actually let's start where we ended it in. The previous lessons kind of demonstrate something about the right and left outer join their actually interchangeable. If you reverse the way they're reading their written, you can use a left outer and a right out of joint
to reach the same results set.
It kind of becomes a perspective of the programmer involved in writing the query. So let's take a look at what this looks like.
So here we have the previous query we wrote in the previous lesson.
Let's go ahead and just switch this to ah, right, outer join.
So right now we are right. Our joining on the department manager table. So B is the department manager table and a is the employees table. So our results set should shrink down toe on Lee the things that exist in V, and we'll also pull in the related data from the employee table.
Now the related data is defined is the MP alias?
So, for example, Empta employee number will come in from
are the employees table.
So let's go ahead and run this
and we see that our data set has indeed shrink, and it's fairly similar to the inner join that we used in a previous lesson.
However, if there were entries and the department table that did not exist in the employees table, we would get department injuries with no foot employee number. But that didn't occur in this test data, which is pretty much expected. So let's see if we can change this to be the same results set
that we used in the previous lesson,
and to exchange to make that change is actually pretty easy. So what I'm going to do is I'm just going to copy
to this or better state. I'm going to cut it.
I'm going to paste it in the above statement and the from table, I'm gonna cut out the other table. So I've replaced the previous table with the department manager table.
I'm gonna pace that in place of the demon alias table that I was using previously. I will make sure the spacing is correct.
Now, if I run this
a lot of noes back, let's go ahead and sort by the department number
And sure enough, we ended up with same data set that we used when we had a left out of joint. What we did is we swapped the tables and then called it right out or join and got the same answer.
So the thing to keep in mind here is that you could rotate this where B is on the left and a is on the right and then switch the joint type and get the exact same data type back.
So if you happen to hear someone say, Well, you have to use a left outer join. That's not necessarily true. And if you change the perspective, you can use the right out of joint to get to the same data set. So that's something to keep in mind when working with left outer joints and right outer joins. Because sometimes you might be thinking yourself.
Which one should I use? And the answer is, Well, you could use either one. It's kind of
what perspective are you looking at the tables from? Well, that completes this lesson. I hope you got your right outer Join working. And I hope you learn some things about the left and the right outer joins and how they can sometimes be interchanged.
I will see you in the next lesson. Thank you.
Penetration Testing and Ethical Hacking
The Penetration Testing and Ethical Hacking course prepares students for certifications, like CEH. This course ...
7 CEU/CPE Hours Available
Certificate of Completion Offered
This free course introduces the student to intermediate concepts found in the implementation and application ...
10 CEU/CPE Hours Available
Certificate of Completion Offered