join and PK where and

ONE .left join and

left join and也是以A表的记录为基础的,A可以看成左表,B可以看成右表,left join and是以左表为准的。换句话说,左表(A)的记录将会全部表示出来,而右表(B)只会显示符合搜索条件的记录(例子中为: A.ID = B.ID)。B表记录不足的地方均为NULL,加上and条件后,A表记录也将全部被表示出来,而B表只会将符合条件的记录显示出来,B表记录中不符合条件的地方均显示为null。

select a.id,a.name,b.id,b.subject,b.score from tmp_lxq_1 a
left join tmp_lxq_2 b
on a.id=b.id
and b.score>=80;

ID NAME ID SUBJECT SCORE
1 张三 1 语文 80
2 李四 2 数学 90
3 王五

TWO .left join where

left join where条件是在临时表生成好后,再对临时表进行过滤的条件。这时已经没有left join的含义(必须返回左边表的记录)了,条件不为真的就全部过滤掉。

select a.id,a.name,b.id,b.subject,b.score from tmp_lxq_1 a
left join tmp_lxq_2 b
on a.id=b.id
where b.score>=80;

ID NAME ID SUBJECT SCORE
1 张三 1 语文 80
2 李四 2 数学 90

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值