一个左连接查询的例子

项目中遇到的情况,需要查询广告主所有的广告及登录的网站主是否申请的状态,广告与网站主的关系存在fh_ad_webmaster 表中。

  1. select a.id id,   
  2.        e.status status,   
  3.        a.name name,   
  4.        a.type type,   
  5.        a.picSize picSize,   
  6.        a.checkType checkType,   
  7.        a.startTime startTime,   
  8.        a.endTime endTime,   
  9.        c.AdMaster AdMaster,   
  10.        c.signPic signPic,   
  11.        c.webUrl webUrl,   
  12.        c.webName webName,   
  13.        d.id cid,   
  14.        d.catelogName catelogName,   
  15.        b.detailExplanation detailExplanation,   
  16.        b.squeezePercent squeezePercent,   
  17.        b.createTime createTime,   
  18.        b.type paytype,   
  19.        b.squeeze squeeze,   
  20.        c.companyName companyName,   
  21.        a.picPath picPath,   
  22.        a.linkText linkText   
  23. from fh_ad_base a   
  24.      left join fh_ad_paynormal b on a.merchanter = b.adMasterId  and a.getMoneyType=b.id   
  25.      left join fh_union_admaster c on c.AdMaster = a.merchanter    
  26.      left join fh_union_catalog d on c.webType = d.id   
  27.      left join fh_ad_webmaster e on e.acId = a.id and e.webMasterId =   
  28.       'ff808081167b0fac01167b1d470e0004'  
  29. where a.merchanter = 'ff808081167b0fac01167b1c794e0001' and  
  30.       a.status = 1   
  31. order by id desc  
  32. 或者

 

    1. select    
    2. a.`name` adname,a.`type` adtype,a.`picSize` size,a.`putinType` puttype,   
    3. a.`checkType` checktype,a.`startTime` starttime,a.`endTime` endtime,   
    4. a.`picPath`,a.`linkText` linktext,   
    5. b.`namename ,b.`squeezeType` squeezeType,   
    6. c.`AdMaster` admaster, c.`companyName` comanyname,c.`signPic` signpic,c.`webName` webname,   
    7. c.`webUrl` weburl,   
    8. d.`catelogName`,d.id cid,   
    9. e.`status` entersataus   
    10. from `fh_union_admaster` c ,`fh_union_catalog` d,`fh_ad_paynormal` b,   
    11. `fh_ad_base` a left OUTER JOIN `fh_ad_webmaster` e on a.`id`=e.`acId` and e.`webMasterId`='ff808081167b0fac01167b1d470e0004'  
    12. WHERE a.`getMoneyType`=b.`id` and c.`AdMaster`=a.`merchanter` and d.`id`=c.`webType`   
    13. and a.`merchanter`='ff808081167b0fac01167b1c794e0001' and a.`status`=1  
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

1598583

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值