select * from tbl where rid = 6 and id in (select id from tbl where rid = 7)

解决方案 »

  1.   

    select * from tbl where rid = 6 and id in (select id from tbl where rid = 7)楼主你是不是弄错了?这条语句不就等于select * from tal where rid=6 and rid=7吗?
      

  2.   


    select id from tbl as t1 inner join tbl as t2 using(id) where t1.rid = 7 and t2.rid = 6;
      

  3.   


    这两者并不等价,我原sql的意思是要取出rid为6和rid为7的交集!但条件rid=6 and rid=7的结果则为空集!一个字段的值是唯一的,即等于6又等于7,怎么可能?
      

  4.   

    select distinct a.*
    from tbl a , tbl b
    where a.rid=6
    and b.rid=7
    and a.id=b.id
      

  5.   

    select a.*
    from tb1 a join tb2 b on a.id=b.id
    where a.rid=6 and b.rid=7;
      

  6.   


    select a1.* 
    from (select * from tbl where rid = 6) a1 , (select id from tbl where rid = 7) a2
    where a1.id = a2.id