多表join查询

最近做项目,需要查询连接多个表后与一个表左连接查询,在网上查了很多的资料,没有找到解决的办法,郁闷了我好几天,今天终于试出来了。高兴了一把。
SQL语句操作方式一:
select distinct a.id, c.first_name as owner_name,f.stuname,f.stusexname,f.cardno,f.orgincardno,f.classname,f.state,f.createtime
e.classzone_id,b.school_id from people b,profiles c ,roles d,schools s,
classzone_memberships e,classzones g,users a LEFT JOIN t_consume_card t on t.stuid= a.id
where a.id = b.owner_id and b.id = c.person_id
and b.id = d.person_id and b.id = e.person_id and g.id=e.classzone_id
and s.id=b.school_id and s.id=246 and d.name='student';
左连接的两表必须放在left join的前后,后面可以跟where条件,不能用and而是where。
SQL语句操作方式二:
SELECT * from business_handle as f RIGHT JOIN (select distinct a.id,c.first_name as owner_name,e.classzone_id,b.school_id from users a,people b,profiles c ,roles d,
classzone_memberships e,classzones g where a.id = b.owner_id and b.id = c.person_id and b.id = d.person_id and b.id = e.person_id and g.id=e.classzone_id) as h and f.owner_id = h.id where条件
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值