例如: select 100 in (select id from table1)结果如果存在是1, 不存在是0我现在想做一个query, 把一个id集合(100,101,102...)传入, 像这样select 100,101,102,103,104 in (select id from table1)明显这个语句的结果是100,101,102,103是列, 104 in (select id from table1)的结果是另一列了,不是我想要的.我要的是返回匹配的ID集合, 例如100,101是匹配的,查询结果看起来像:100
101
谢谢.

解决方案 »

  1.   

    select  id  from table1 where find_In_set(id  ,'100,101,102,103,104');
      

  2.   

    too slow...不如创建一个新表做子查询了...
      

  3.   

    是啊, find_in_set无法用索引...看来只能用你说的方法了, 也就是一开始我就在用的, 只不过创建一个表麻烦点..
      

  4.   

    或者用select count(*) from table1 where id in (100,101,102...)
      

  5.   


    再问下另一个问题:表test里有一个unique field - ID, 现在insert ignore test(id) values (1), (2), (3)..;
    这样可以安全的插入不存在的id吗? 换句话说遇到重复id就不插入...
      

  6.   

    mysql help:
    INSERT IGNORE in the treatment of new rows that contain unique key values that duplicate old rows: The new rows are used to replace the old rows rather than being discarded.新的记录替换旧的记录
      

  7.   

    如果数字不是上百,非常多,你还不如直接生成SQL语句select id from table1 where id =100
    union all
    select id from table1 where id =101
    union all
    ...
    union all
    select id from table1 where id =104