select  m.name,m.merchant_id,c.*
   from couponinfo c,merchant m, coupon_merchant cm 
   where c.coupon_id=cm.product_id
   and cm.merchant_id=m.merchant_id
   and c.coupon_name = 'text'这样查出来是 多条数据! 如何取出 m.merchant_id 最大的那条记录

解决方案 »

  1.   

    with t as (
    select m.name,m.merchant_id,c.*
      from couponinfo c,merchant m, coupon_merchant cm  
      where c.coupon_id=cm.product_id
      and cm.merchant_id=m.merchant_id
      and c.coupon_name = 'text')
    select * from t where merchant_id=(select max(merchant_id) from t); 
      

  2.   

    不对啊 ! 执行报错 ora-01722
      

  3.   

    select ROWNUM,m.name,m.merchant_id,c.*
      from couponinfo c,merchant m, coupon_merchant cm  
      where c.coupon_id=cm.product_id
      and cm.merchant_id=m.merchant_id
      and c.coupon_name = 'text' AND ROWNUM = 1
      ORDER BY m.merchant_id DESC
      

  4.   


      select rownum,t.* from
      (select m.name,m.merchant_id,c.*
      from couponinfo c,merchant m, coupon_merchant cm 
      where c.coupon_id=cm.product_id
      and cm.merchant_id=m.merchant_id
      and c.coupon_name = 'text'
      order by m.merchant_id desc) t
      where rownum=1;
    没数据就没试,不知道行不行,你试试
      

  5.   

    如:
    select id from user_city where rownum=1 order by id desc;