Thursday 16 April 2015

MYSQL-JOIN-EXAMPLES-PRACTICES

Step 1:

Create table lefttable:


create table lefttable
(id  int(10),
name  varchar(20),
city   varchar(20));



Create table righttable:


create table righttable
(id  int(10),
fname  varchar(20),
fcity   varchar(20));


Note: enter some values & some same id value into both tables ..

Step 2:

(1) Simple join  example :

select  l.name,r.fname  from  lefttable l , righttable r;




(2)Left Join   example:

select  l.name,r.fname from lefttable l  LEFT JOIN  righttable r ON l.id=r.id;


(3)Right Join   example:

select  l.name,r.fname from lefttable l  RIGHT JOIN  righttable r  ON  l.id=r.id;


(4)Inner Join   example:

select  l.name,r.fname from lefttable l  INNER JOIN  righttable r  ON  l.id=r.id;

No comments:

Post a Comment