使用LEFT OUTER JOIN在单个查询中联接多个表


JOIN multiple tables in single query using LEFT OUTER JOIN

在多个表中使用LEFT OUTER JOIN时遇到困难。

我的表是:countriescustomer_infopackage_typesservice_typesshipping_info

这是我迄今为止的代码:

$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为null。但我无法找出错误。

感谢您的帮助。

您的查询可能存在以下手动错误:

表名字段名

不匹配