📜  sql 值不在另一个表中 - SQL 代码示例

📅  最后修改于: 2022-03-11 15:05:30.785000             🧑  作者: Mango

代码示例1
-- Find missing t1 values in t2 (based on 'id' field)
SELECT * FROM t1 WHERE t1.id NOT IN (SELECT id FROM t2);
-- or
SELECT * FROM t1 WHERE NOT exists (
    SELECT NULL FROM t2 WHERE t2.id = t1.id
);
-- or
SELECT t1.* FROM t1 LEFT OUTER JOIN t2 ON t2.id = t1.id WHERE t2.id IS NULL;