select ... from a,(select distinct bid from b) b
where b.bid=a.bid;

解决方案 »

  1.   

    sorry
    如果你需要 b 中的其他字段值的话这样还不行select ... from a,b
    where b.bid=a.bid and b.rowid =
    (select max(rowid) from b bb where bb.bid = b.bid);
      

  2.   

    select ... from a,(select id,max(bid) b_id from b group by id) s
    where a.id=s.id
      

  3.   

    如果需要其它字段可以这样
    select ... from a,(select id,a1,a2,...,an,max(bid) b_id from b group by id,a1,a2,...,an) s
    where a.id=s.id
      

  4.   

    如果要加其它字段可以这样
    select ... from a,(select id,max(bid) b_id,max(f1),max(f2),...,max(fn) from b group by id) s
    where a.id=s.id
      

  5.   

    select ... from a,(select min(bid) bid from b) b
    where b.bid=a.bid;
      

  6.   

    按照楼主的意思好像b.id 和bid不是一回事吧,Table A 中有bid吗?select ...
    from a,b
    where a.id  = b.id
      and b.bid = (select min(b_se.bid) from b b_se where b_se.id = b.id)
      

  7.   

    没错,Table A中没有bid.还有就是,A中有的,B中不一定有,要将A的记录每条都Select出来,如果B中有的就将第一条对应上。就是相当于连接(join),但又不同于一般的连接。B中有多条记录的只要一条。
      

  8.   


    select ... from a,b
    where b.bid=a.bid and b.rowid =
    (select max(rowid) from b bb where bb.bid = b.bid)
    union all
    select .... from a,b where a.bid = b.bid(+) and b.bid is null;
      

  9.   

    select ...
    from a,
        (select * from b where b.rowid in (select min(rowid) from b group by id)) b_se
    where a.id = b_se.id(+)
      

  10.   

    参考大家的答案,我自己搞定了,select a.id,b2.bid,... from a,(select id,bid,.. from b b1 
         where b.bid=(select min(bid) from b where id=b1.id)) b2
    where b2.id(+)=a.id谢谢大家
      

  11.   

    biti兄:
    应该把bid 都换成 id 吧 :)
      

  12.   

    yes 
    you are right