sql之left join、right join、inner join的区别

left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 
right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录
inner join(等值连接) 只返回两个表中联结字段相等的行

有下面两张表

表一:formone

表二 :formtwo

1.left join

 返回包括左表中的所有记录和右表中联结字段相等的记录 

select * from formone fo left join formtwo ft on fo.id = ft.id;

select * from formone fo ,formtwo ft where fo.id = ft.id(+);

得到的结果是:

2.right join

返回包括右表中的所有记录和左表中联结字段相等的记录

select * from formone fo right join formtwo ft on fo.id = ft.id;

select * from formone fo ,formtwo ft where fo.id(+) = ft.id;

得到的结果是:

3.inner join

只返回两个表中联结字段相等的行

select * from formone fo inner join formtwo ft on fo.id = ft.id;

select * from formone fo ,formtwo ft where fo.id = ft.id;

得到的结果是:

 

posted @ 2018-08-08 10:26  坚持就是胜利66  阅读(346)  评论(0)    收藏  举报