就看你的 in (1,2,......)这个数据是什么来的? 如果是在一个table 里面 select * from ta a where exists(select 1 from tb b where a.id=b.id)如果是个字符串 select * from tb where charindex(','+cast(id as varchar)+',',',1,2,3,4,5,...')>0
先确认条件字段有索引 再把条件写入一个临时表,如#t然后: select * from A where exists(select 1 from #t where a.id=临时表字段名) 或: select a.* from A join #t b on a.ID=b.临时表字段名
如果是在一个table 里面
select *
from ta a
where exists(select 1 from tb b where a.id=b.id)如果是个字符串
select *
from tb
where charindex(','+cast(id as varchar)+',',',1,2,3,4,5,...')>0
再把条件写入一个临时表,如#t然后:
select * from A where exists(select 1 from #t where a.id=临时表字段名)
或:
select a.*
from A
join #t b
on a.ID=b.临时表字段名