微擎数据操作之联表查询

-SQL语法 
select * from table1 left join table2 on table1.条件列名 = table2.条件列名;
-sql语句:

SELECT *
from ims_domall_zc_order left JOIN ims_domall_zc_member on ims_domall_zc_member.openid=ims_domall_zc_order.openid 
LEFT JOIN ims_domall_zc_goods on ims_domall_zc_goods.id=ims_domall_zc_order.goods_id 
WHERE ims_domall_zc_order.uniacid=1

-多表联表查询,微擎联表查询SQL语句

$sql="select o.* , m.realname as realname,m.phone as phone,m.nickname as nickname ,a.title as title from " . tablename("domall_zc_order") . " o"  . " left join " . tablename("domall_zc_member") . " m on m.openid=o.openid  " . " left join " . tablename("domall_zc_goods") . " a on a.id=o.goods_id  "." $where ORDER BY o.ordersn DESC ";

-查询

 $orderse=pdo_fetchall($sql,$params);

你可能感兴趣的:(微擎,sql)