关于连接查询中的交叉连接、左外连接、右外连接、全外连接以及内连接

关于这几个连接查询,举例一看就清清楚楚了

table1
idname
1张三
2李四
3王五
4赵六
table2
mathenglishid
66872
77653
88546
99657
99759


那么下面就一个个来说明:

1.交叉查询(笛卡尔积)

select * from table1,table2  这个查询出来的数据应该为20*5的表,由于这个比较长,我就不具体例举出来。笛卡尔积应该是很简单很好理解的。

2.内连接

select  t1.*,t2.* from table1 t1,table t2 wheret1.id=t2.id;

或者selec t1.*,t2.* from table1 t1 inner jion table t2 on t1. 

内连接
idnamemathenglishid
2李四66872
3王五77653

3.左外连接

select  t1.*,t2.* from table1 t1,table t2 where t1.id=t2.id(+);

左外连接
idnamemathenglishid
1张三nullnullnull
2李四66872
3王五77653
4赵六nullnullnull
4.右边外连接
select  t1.*,t2.* from table1 t1,table t2 where t1.id(+)=t2.id;
右外连接
idnamemathenglishid
2李四66872
3王五77653
nullnull88546
nullnull99657
nullnull99759
5.全外连接

select  t1.*,t2.* from table1 t1 full outer jion table2 t2ont1.id=t2.id;

全外连接
idnamemathenglishid
1张三nullnullnull
2李四66872
3王五77653
4赵六nullnullnull
nullnull88546
nullnull99657
nullnull99759
























  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值