检查另一个表的第一个查询结果的引用

时间:2013-09-09 15:06:32

标签: sql oracle

我有以下查询

SELECT abm_took_id FROM pos_took WHERE DELETEDDATE IS NOT NULL

从表abm_took_id中获取pos_took的值。

现在有另一个表pos_eook由列cbm_bookid组成,这是一个外键,这是第一个表(pos_took)主键abm_took_id是一个表格第二个表格(pos_eook)的关键字为cbm_bookid

现在我必须检查第一个查询引用中的abm_took_id提取是否存在于第二个表中,例如abm_took_id=44555从第一个查询中取出,现在它存在于第二个表中,请告知查询我可以在哪里使用或存在运营商。

1 个答案:

答案 0 :(得分:1)

如果您尝试在第一个表(查询)中找到不在第二个表中的所有引用:

SELECT abm_took_id
FROM pos_took
WHERE DELETEDDATE IS NOT NULL and
      abm_took_id not in (select cbm_bookid
                          from pos_eook
                          where cbm_bookid is not null
                         );