您可以NOT IN
像这样使用谓词:
SELECT *
FROM YourTableName
WHERE ReferenceId NOT IN(10437, 10476, 13212, 13215);
更新:如果您想要存在的 Id,请使用IN
谓词:
SELECT *
FROM YourTableName
WHERE ReferenceId IN (10437, 10476, 13212, 13215);
更新 2:要清除此问题,您需要表中不存在的 id 列表中的 id 列表。想法相同,但方式不同
SELECT FROM (list of ids) WHERE id NOT IN (SELECT referenceid from Table);
不是这个:
SELECT FROM Table WHERE id not in (list of ids ) will give you the other list;
因为这将给出 id 列表中不存在的表中的 id 列表。
你可以这样做:
SELECT *
FROM
(
SELECT 10437 id
UNION ALL
SELECT 10476
UNION ALL
SELECT 13212
UNION ALL
SELECT 13215
) t1
WHERE id NOT IN (SELECT referenceid FROM YourTableName);
或者RIGHT JOIN
像这样:
SELECT t2.Id
FROM YourTableName t1
RIGHT JOIN
( SELECT 10437 id
UNION ALL
SELECT 10476
UNION ALL
SELECT 13212
UNION ALL
SELECT 13215
) t2 ON t1.ReferenceID = t2.id
WHERE t1.referenceid IS NULL;
两者都应该返回:
10476
13212