选择存在于tA表中,但其中name不同于tB表中的数据
select id, name, gender, classId from tA where not exists (select name from tB where tA.name=tB.name)
not in 的写法,同样的效果,但是在大数据量的时候效率不高
select id, name, gender, classId from tA where name not in (select name from tB where tA.name=tB.name)
或者
select id, name, gender, classId from tA where name not in (select name from tB)
如果选取和排除的字段数目相等,还可以用except方法,但是注意它会去除重复的数据(有点类似于union和union all的区别,不过并没有except all这种用法)
select name from
tA except select name from
tB
本文介绍了如何使用SQL查询来筛选特定数据,包括使用not exists、not in以及except方法从一个表中选择那些不在另一个表中的记录。这些技巧对于进行数据对比非常有用。
3199

被折叠的 条评论
为什么被折叠?



