SQL:选择表A中所有不在表B中的唯一值 [英] SQL: select all unique values in table A which are not in table B

查看:120
本文介绍了SQL:选择表A中所有不在表B中的唯一值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有表A

Id  | Name      | Department
-----------------------------
0   | Alice     | 1
0   | Alice     | 2
1   | Bob       | 1

和表B

Id  | Name
-------------
0   | Alice     

我想选择表A中所有不存在于表B中的唯一ID.我该怎么做?

I want to select all unique Ids in table A which do not exist in table B. how can I do this?

推荐答案

select distinct id 
from TableA a
where not exists (
    select id 
    from TableB 
    where id = a.id
)

这篇关于SQL:选择表A中所有不在表B中的唯一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆