好的我有一个人和我有一个表和Id列有成千上万的记录...我有另一个逗号分隔的ID列表
1, 2, 457, 558, 998
我想查看这个人员表,看看哪5个记录不存在......
我试过
select id from people where id not in (1, 2, 457, 558, 998)
但这会返回所有其他千条记录,而不仅仅是这5条记录中找不到的记录
我缺少的任何想法
答案 0 :(得分:2)
select a.id
from (
select 1 as id
union all
select 2
union all
select 457
union all
select 558
union all
select 998
) a
left outer join people p on a.id = p.id
where p.id is null
如果您要检查的值位于表格中,则可以执行以下操作:
select c.id
from MyCheckValues c
left outer join people p on c.id = p.id
where p.id is null
答案 1 :(得分:1)
可能是这样的:
Select id from people where id in (1, 2, 457, 558, 998)
and id not in ( select id from people )
答案 2 :(得分:0)
SELECT id FROM people WHERE id IN (1, 2, 457, 558, 998)
如果您有每个“id”的倍数,请使用:
SELECT DISTINCT(id) FROM people WHERE id IN (1, 2, 457, 558, 998)