我有一个包含ids和ids列表(1,3,4,5,2,29,24)的表。我可以使用下面的查询在表中查看该列表中的哪些in:
select * from tbl1 where id in (1,3,4,5,2,29,24)但是,是否可以在不创建临时表的情况下查看此is列表中不存在于tbl1中的数字?就像这样
select * from tbl1 where (1,3,4,5,2,29,24) not in id发布于 2015-12-05 00:52:50
您可以在查询中使用派生表:
select id
from (select 1 as id union all select 3 union all select 4 union all select 5 union all
select 2 union all select 29 union all select 24
) id
where not exists (select 1 from tbl1 where tbl1.id = id.id);如果您想查看既在表中又不在表中的ids,则使用left join
select id.id, tbl1.*
from (select 1 as id union all select 3 union all select 4 union all select 5 union all
select 2 union all select 29 union all select 24
) id left join
tbl1
on tbl1.id = id.id;发布于 2015-12-05 08:46:23
select * from tbl1 where id not in (1,3,4,5,2,29,24)
https://stackoverflow.com/questions/34093373
复制相似问题