table1
id1
1
2
3
4
table2
id1  id2
1    1
1    2
1    3
2    1
2    2
2    3
3    1
3    2
3    3两表关联,找出id2为1 & 2 & 3的所有id1,要经得起压力测试,数据量100万

解决方案 »

  1.   


    select id1 from table2 where id2=2 group by id1 order by id1;
      

  2.   

    不是这样子的,我要找id2为 1,2,3的所有id1,谢谢
      

  3.   


    select id1 from table2 where id2 in (1,2,3);
      

  4.   

    给ID2建立一个索引,你才 100W的数据。
      

  5.   

    select id1 from table2 where id2 in (1,2,3);in是or的关系,即id2=1 or id2=2 or id2=3;我要的是and的关系,即id2=1 and id2=2 and id2=3
    我现在是用别名的方法实现的:
    select a.id1 from table2 a,table2 b,table2 c where a.id2=1 and b.id2=2 and c.id2=3 and a.id1=b.id2 and b.id1=c.id1
    这样关联起来的表比较多,由于数据本身很大,而且还有其他的表、其他条件,所以速度很慢,能不能帮忙改进一下,谢谢!