有这样一个id数组,数据库中对应有一张表,表中记录有id,现在要把数组中没有记录在数据库中的挑选出来,如何办呢?not in的情况好像跟这个刚刚相反。

解决方案 »

  1.   

    where find_in_set(id,传入数组)>0
      

  2.   

    数组没在数据库中怎么select呢?请明示!
      

  3.   

    可行。但插入也是需要开销的。比如数组 arrayX[N]方法一\
    for each @x in arrayX { select id from table1 where id=@x)方法二\
    for each @x in arrayX { @s += @x + "),(" }
    insert into tableTemp (id) values @s;
    select * from tableTemp where not exists (select 1 from table1  where id=tableTemp .id)效率上明显可以分析出差异。
      

  4.   

    在mysql一次性insert多行不就可以了?
      

  5.   

    1、如果表中数据不大的情况下可以将ID都读取出放在集合(allIdList)中。
    2、定义一个集合notinDBList
    for(int i=0;i<id数组.size;i++){
        if(!allIdList.contains(id数组[i])){
           notinDBList.add(id数组[i]));
        }
    }
    3、最后notinDBList里面存的就是你要的结果