Left join.
So the left join or left outer join keywords return all records from table one, which is the left table
and the matched records from table two, which is the right table, and the result is null from the
right side if there is no match.
So in other words, the school left join returns all rows from the left table, even if there are no
matches in the right table.
So this means that if the end clause matches zero records in the right table, the join will still return
a row in the result.
Yeah, but with null in each column from the right table.
So does that mean it means that if a left join returns all the values from the left table plus matched
values from the right table or no.
In case of no matching join predicate.
Mm hmm.
So let's jump enthusiasms and do some examples so that we can understand it a little better.
So the left join will return all the records from the left table in the joint cause, regardless of
matching records in the right table.
And a left ask you all outer join includes rows where the condition is met, plus all the rows from
the table on the left where the condition is not met.
And fields from the right table with no match will be displayed as null values.
So the first table that we're going to retrieve data from is the product table and the production schema.
And this table will be the left table and it stores many product related features, but will retrieve
only the name and column from this table right now.
The second table will be the sales order detail table in the sales schema.
And the ordered products are stored in this table.
So if a product is in this table, it means that it has been ordered.
So what we're going to do is we will retrieve the column sales order detail idea from this table.
And we'll make this table the right table.
Now, when we look at the columns of these tables, we will notice that these tables have a relation
on the column product I.D. So both tables have the product ID column.
Now in this example, we're going to find out if a product has been ordered so far.
If the product has a sales order detail idea, it means that the product has been ordered before.
And if the sales order, detail, ideas and all that means that the product has not been ordered yet.
And then when we execute the query, we will see that there are many products that have a no sales order
detail.
Indeed, and that means that the products haven't been ordered yet.
The left joined keyword.
Returns all records from the product table, which is on the left table.
And if there are no matches in the sales order detail, which is the right table?
McCollum's sales order detail I.D. from the sales order detail table with no match has been displayed
as a null value.
Now the alias also can be used instead of tables, so letter P will be used as table product.
And let's use the letter S for the sales order detail table.
And the left outer join keywords can be used instead of the left join keywords and the same result will
be displayed.
Right.
Join.
So the right join or the right outer join keywords return all records from table two, which is on the
right and the matched records from table one, which we're calling our left table.
And the result is no.
From the left side when there is no match.
So in other words, the right joint keyword returns all records from the right table, even if they're
no matches from the left table.
So then in this example, the table production is the left table and the table sales order detail is
on the right.
And the right joint keyword will return all records from the table sales order detail even if there
are no matches in the table production.
So in this example, we're going to retrieve all ordered product with right joint.
Now before executing the query for the right join clause.
Here is the result of the left join cause all products ordered or not ordered in the table product and
all ordered products in the table sales were to detail have been listed.
There are 121,555 rows.
So if we execute the right joint query.
121,317 rows are listed.
Why don't we verify if the result is correct or not?
Sales ordered detailed table stores, the ordered products.
So that means that each product in the table sales order detail is also in the product detail.
So.
If we had a where clause to the left join query in order to find the no sales order detail ID, we will
find the products which haven't yet been ordered in the product table.
Execute the query.
And here is a result.
238 products haven't yet been ordered.
So these records are only in the table product.
So if we add this result to the rose count of the right joint statement, we should get the rows count
of the left joint statement.
You follow?
And the result is 121,555, which is the result of the left joint statement.
So this result is also the sum of all data from these two tables.
The right joint keyword can be used instead of the right outer join keyword.
And it won't change the results.