Leave a comment

SQL: Understanding JOINS

SQL JOINS are required when you want to match values from different tables and get the common result out of it. Depending upon various criteria we can used different joins mainly INNER Join, LEFT OUTER Join, RIGHT OUTER Join and FULL OUTER Join. Let us explore each of these type of joins in detail

Data Set

We have two tables customer and seller and the data from these two tables is shown below:

Customer table

customer_table

Seller table

seller_table

INNER JOIN

INNER join returns all the rows from both the tables where the join condition is met.

select * from customer
INNER JOIN seller
on customer.cust_name = seller.sell_name

inner_join_result

LEFT OUTER JOIN

LEFT OUTER join returns all the rows from the left table that are matched on the join condition along with the unmatched rows, for unmatched rows it will put null in the result

left_outer_join_result

RIGHT OUTER JOIN

RIGHT OUTER JOIN returns all the rows from the right table that are matched on the join condition and also returns the unmatched rows, for unmatched rows it will put null in the result

right_outer_join_result

FULL OUTER JOIN

Full outer join returns all the possible rows that are matched from both the tables and also returns the unmatched rows from both the tables, it will place null for the unmatched rows

full_outer_join_result

Leave a Reply

Your email address will not be published.


2 − one =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>