MySQL的双表多表联查

最近在做EC-Mall的二次开发,遇到这么一个需求,将挂件单独显示成一个页面。由于EC-Mall的挂件是用数据模块+模块类库的方式进行的,就是使用类似smarty的形式。而单独一个页面的话,数据读取需要自己写SQL语句。

现在的问题是,需要将商品中的汽车类中的推荐商品数据显示出来,sql如下:

1 select from shop_goods as a
2     join shop_recommended_goods as b
3     where a.goods_id = b.goods_id
4     and b.recom_id = 36
5     order by b.sort_order asc
6     limit 14

其中,表shop_goods是存储了所有商品信息的数据表,shop_recommended_goods则是将商品id与推荐id相关联的表。

MySQL多表联查例子:

下面这两个MySQL多表联查方法都可以,inner join on 更好点。表结构没贴出来,但比较好懂了。

MySQL多表联查的简单方法:

1 select c.nom, e.nom  
2 from consultant c, affaire a, besoin b, salarie sa, site s, entreprise e 
3 where c.consultant_id=a.consultant_id and a.besoin_id=b.besoin_id and  
4 b.salarie_id=sa.salarie_id and ssa.site_id=s.site_id ands.entreprise_id=e.entreprise_id 

MySQL多表联查的inner join方法:

1 select c.nom, e.nom 
2 from consultant c 
3 inner join affaire a on c.consultant_id=a.consultant_id 
4 inner join besoin b on a.besoin_id=b.besoin_id 
5 inner join salarie sa on b.salarie_id=sa.salarie_id 
6 inner join site s on ssa.site_id=s.site_id 
7 inner join entreprise e on s.entreprise_id=e.entreprise_id 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值