我有以下查询
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
从第一个查询中取出,现在它存在于第二个表中,请告知查询我可以在哪里使用或存在运营商。
答案 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
);