sql:检查表B中是否存在表A中的条目 [英] sql: check if entry in table A exists in table B

查看:65
本文介绍了sql:检查表B中是否存在表A中的条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个定义表,我知道它维护得不太好,我们称之为table A.我有另一个表(称为table B),该表要小得多,理想情况下应该是subset of table A,但我知道table A有点陈旧,并且不包含Table B中的新条目.

I have a definition table that I know is not being maintained very well, lets call this table A. I have another table (call it table B) that is much smaller and ideally should be a subset of table A but I know that table A is somewhat stale and does not contain new entries that are in Table B.

请注意,表A和B的列不同.

Note, that tables A and B have different columns.

Table A:
ID, Name, blah, blah, blah, blah

Table B:
ID, Name

我想要表B中的所有行,以使表B中的ID在表A中不存在.我只希望表B中的ID在表A中根本不存在的行.

I want all rows in Table B such that the ID in Table B does NOT exist in Table A. This does not just match rows in Table A; I want only rows in Table B where the ID does NOT exist at all in Table A.

推荐答案

SELECT *
FROM   B
WHERE  NOT EXISTS (SELECT 1 
                   FROM   A 
                   WHERE  A.ID = B.ID)

这篇关于sql:检查表B中是否存在表A中的条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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