sql语句中的join连接(左连接、右连接、全连接、内连接)

内部连接(inner join): select * from d_user a inner join D_ORGANIZATION b on a.COMPANY_XID=b.ID  内部链接也是排他连接。连接条件相同则会组建一条记录。

                             内部链接为默认的连接。一般会把inner关键字省略。( select * from UserInf,org where UserInf.id=org.orgId 内部连接)

外部连接(outer join):分为 左连接和右连接  left  join和 right join 或者 left outer join和 right outer join 。join左侧的表为左表,右边的为右表。

                            左连接以左表为基础。右连接以右表为基础。

完全连接(full join): select * from UserInf a full join org b on a.id=b.orgId

结果:                     

id name orgId orgName
1 刘广法 1 菏泽
1 刘广法 1 济宁
2 刘广飞 2 临沂
3 刘广伟 NULL NULL
NULL NULL 4 烟台

交叉连接(笛卡尔积): a表中每个记录都与b表中的记录连接

 

posted on 2016-02-01 18:08  刘广法01  阅读(5569)  评论(0编辑  收藏  举报