sql joins

If you want to be a developer then you must be aware about sql joins. This is really important. Well joins are use to create a relation between two or more tables. I created two tables “Customers” and “Orders”

Customers

sql joins

 

 

 

 

 

 

 

The above table shows Customers detail

Orders

orders

 

 

 

 

 

 

 

The above table shows orders detail

Inner Join

select C.name,C.email,O.id,O.order_date from customers C join orders O on O.customer_id = C.id “

here i created alias “C” for customers and alias “O” for orders and i joined them through O.customer_id = C.id . The result will be

inner join

 

 

 

 

 

 

It got detail for all customers who’s Customer Id available in orders table. You don’ see records of ┬áparmod and dicky because id 5,6 not available in orders table

Left Join

select C.name,C.email,O.id,O.order_date from customers C left join orders O on O.customer_id = C.id

 

 

 

 

 

 

 

look at the difference with left join here you can see records of parmod and dicky but id and order_date is null . It will fetch records of left table

Right Join

select C.name,C.email,O.id,O.order_date from orders O right join customers C on O.customer_id = C.id

right

 

 

 

 

 

 

 

Right join is similar to left join . look at the query difference.

Inner joins are really important. There is 90% use of inner joins in almost every big projects. Joins are really important when you are going for interview. You must read this Tutorial before going for interview.

 

 

sql joins

You May Also Like

Leave a Reply

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