标签:
当order表中openid等于当前openid,order表里的mendian字段与mendian里的id字段内容一致时关联mendian与order表,取出表order里的数据
,(as m与as o是把门店表当作m,把order表当作o)
select * from `order` as o left join `mendian` as m on m.id=o.mendian where o.`openid` = ‘$openid‘ order by o.id DESC
order表中的orderid数据取不出,排除错误发现两个表中有共同的字段orderid,于是使用下面的语句
把需要取出的各个表中的字段直接写出
SELECT `order`.`orderid` , `order`.`strshow` , `order`.`create_time` , `order`.`notes` , `mendian`.`corp_name` FROM `order` LEFT JOIN `mendian` ON `mendian`.id = `order`.mendian WHERE `order`.`openid` = ‘$openid‘ ORDER BY order.id DESC
【MYSQL】left join on多个表关联查询(查询的表中有重复名字的字段解决办法)
标签:
原文地址:http://www.cnblogs.com/paofu/p/4609723.html