使用LEFT OUTER JOIN在单个查询中联接多个表 [英] JOIN multiple tables in single query using LEFT OUTER JOIN
本文介绍了使用LEFT OUTER JOIN在单个查询中联接多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在多个表中使用LEFT OUTER JOIN遇到困难.
I'm having difficulties using the LEFT OUTER JOIN in multiple tables.
我的表是:countries
,customer_info
,package_types
,service_types
和shipping_info
到目前为止,这是我的代码:
This is my code so far:
$sql = "SELECT shipping_info.shipping_id, shipping_info.weight, shipping_info.width, shipping_info.height, shipping_info.length, shipping_info.cost, shipping_info.status,
service_types.service, package_types.package_type, countries1.country AS fromCountry, countries2.country AS toCountry, countries3.country AS resiCountry, customer_info.name, customer_info.address
, customer_info.city, customer_info.postcode, customer_info.zipcode, customer_info.phone, customer_info.email, customer_info.country
FROM shipping_info
LEFT OUTER JOIN service_types ON shipping_info.service_type = service_types.serviceType_id
LEFT OUTER JOIN package_types ON shipping_info.package_type = package_types.packageType_id
LEFT OUTER JOIN customer_info ON shipping_info.customer_id = customer_info.customer_id
LEFT OUTER JOIN countries AS countries1 ON shipping_info.from_loc = countries1.country_id
LEFT OUTER JOIN countries AS countries2 ON shipping_info.to_loc= countries2.country_id
LEFT OUTER JOIN countries AS countries3 ON shipping_info.to_id = countries3.country_id";
$statement = $con_db->query($sql);
$result = $statement->fetchAll();
我在最后一行遇到了一个严重错误,我相信这是因为$ result为空.但我无法找出错误.
I'm getting a fatal error in my final line and I believe that's because $result is null. But I'm unable to figure out the error.
感谢任何帮助.
推荐答案
可能是您的查询有以下手动错误:
It may be your query has following manual error:
表名或字段名不匹配
这篇关于使用LEFT OUTER JOIN在单个查询中联接多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文