如何使用exits代替in(in中是具体的值,不是子查询)

(注意:) 我需要in的不是一个表,而是一系列具体的值。

如果是子查询,我们一般可以这样做:

select * from table1 where id in (select id1 from table2)                                  
select * from table1 where exists (select 1 from table2 where id1=id) 

现在是具体的值如:

array[] arr = [1,2,3];

select * from table1 where id in (arr);

这种情况如何可以使用exits,毕竟如果数组元素多的话,效率还是差很远,求解?

自己根据数组去拼接 where里面的sql ;

但是讲道理,速度慢,先应该去看看执行计划,不是硬换; 一般你能用到in ,in里面的数据肯定数据量不大,效果还是可以的

 

临时表

list<Long> list 放123就可以了,
<if test="list != null">
    where id in
    <foreach collection="list" item="item" open="(" close=")" separator=",">
        #{item}
    </foreach>
</if>