select * from table a,table b where a.user_id=b.user_id and a.group_id=1 and b.group_id=2

解决方案 »

  1.   


    select distinct userid from table where userid in (select groupid from table )
      

  2.   


    TO:peytonzwt(涛涛)这种方法总觉得不太好啊!如果我条件多的话,连接的表就很多,SQL也很长。TO: happydreamer(小黑)你的SQL无法达到我所需要的东西!
      

  3.   

    select userid from 表 where Group in (1,2) group by userid having count(distinct group)>=2
      

  4.   

    TO : pengdali(大力 V3.0) 多谢,这个方法不错,我想加分请教如何取俩个记录集的交集,如果用这个方法也可以
    满足上面的要求。多谢了!
      

  5.   

    select distinct a.userid from table a,table b where a.userid=b.userid and a.groupid=1 and b.groupid=2