SQL连接查询 [英] SQL join query
本文介绍了SQL连接查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
选择*来自emp1
select * from emp2
select * from emp2 as e
其中名字不在(从emp1中选择名称,其中id = e.id)
select * from emp1
select * from emp2
select * from emp2 as e
where name not in (select name from emp1 where id=e.id)
id name
5 4444
5 5555
5 2222
5 7777
id name
5 1111
5 7777
6 4444
id name
5 1111
6 4444
Ab ove查询结果如下。但最后我们想通过join获得第3个结果集。但是第3个结果集通过Co相关查询发生
Above Query result are following. but finally we want 3rd result set by join.but this 3rd result set happens through Co-related query
推荐答案
你需要使用LEFT JOIN来实现它
You need to use LEFT JOIN for it
select emp2.*
from emp2 LEFT JOIN emp1 ON emp1.id=emp2.id and emp1.name=emp2.name
where emp1.name IS NULL
这篇关于SQL连接查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文