当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
时间: 2024-11-08 19:30:17