Mysql left right inner and outer join.
Mysql left right inner and outer join.Different between left outer join and right outer join.Different between left outer join and inner join.

Here in this tutorial I am going explain all sorts of sql join those are Mysql left right inner and outer join for retrieving data from two table .Generally sql query fetches data from one table if you would like fetch data from more table with a single query so please follow the below description.lets start all join quey on by one.In below description you will be also getting different between left outer join and right outer join.Also the different between left join and inner join etc..

Suppose I have two tables 1)student 2)teacher
So here teacher_id from teacher table is link to teacher_id of student table.That means we do join between these two table by the help of teacher_id.

So lets see our tables with their data:

Now lets see our query with join:

INNER JOIN:

INNER JOIN gives result of all the matching records from both tables.

Example:

LEFT OUTER JOIN:

LEFT OUTER JOIN is little different from INNER JOIN because it gives extra data(unmatched data) only from left table and set all other data to NULL.

Example:

You can see the above out-put I can explain quickly that is on the above result from student_id 21-25 all have teacher_id is 0 which is not matching with teacher_id of teacher table still that showing in the result beacuse of LEFT OUTER JOIN as it is fetched only unmatched data from left table and you can see all other values are set as NULL as it is not fetching the unmatched data from right table.

RIGHT OUTER JOIN:

Its just opposite LEFT OUTER JOIN because it gives extra data(unmatched data) only from right table and set all other data to NULL

Example:

You can see the above out-put I can explain quickly that is on the above result from teacher_id 6-7 all have student_id is NULL which is not matching with teacher_id of teacher table still that showing in the result beacuse of RIGHT OUTER JOIN as it is fetched only unmatched data from right table and you can see all other values are set as NULL as it is not fetching the unmatched data from left table.

FULL OUTER JOIN:

If you would like to fetch data from bothe table whether it match or not. I will just fetch all.

Example:

Some data bases doesnot support FULL OUTER JOIN then you have to use the logic of UNION.

Mysql left right inner and outer join
The following two tabs change content below.
Jyotiranjan is one of passionate programmer who has been working in magento since 6 years and in the mean time he has developed enormous amount of modules and customisation of sites. He loves to write blogs and travel for long journeying.
Tagged on:         

Leave a Reply

Your email address will not be published. Required fields are marked *