select distinct a.id from a,b where a.id=b.aid

解决方案 »

  1.   

    select distinct id from a
      

  2.   

    select * from a left  join (select * from b b1 where not exists(select 1 from b b2 where b1.aid=b2.aid and b1.id<b2.id))b3
    on a.id=b3.aid
      

  3.   

    to 楼上的两位:这样的话只能有id,我同时需要其它数据啊。如果select distinct a.id as tmpid,* from a,b where a.id=b.aid
    这样id还是不唯一。
      

  4.   

    to CrazyFor(太阳下山明朝依旧爬上来):谢谢你,如果B中没有B.aid=A.id就不需显示A中的数据,如何把这部分的数据给剔除,谢谢!!
      

  5.   

    select * from a join (select * from b b1 where not exists(select 1 from b b2 where b1.aid=b2.aid and b1.id<b2.id))b3
    on a.id=b3.aidleft去掉即可