join left on多张表,使用LEFT OUTER JOIN连接多个表

I'm trying to get data from multiple tales using LEFT OUTER JOIN but I'm getting a fatal error.

Table names, field names, db connection are correct.

$sql = "SELECT shipping_info.shipping_id, service1.service, package1.package_type, countries1.country AS fromCountry, countries2.country AS toCountry, countries3.country AS resiCountry, customer1.name,

FROM shipping_info

LEFT OUTER JOIN service_types AS service1 ON shipping_info.service_type = service_types.serviceType_id

LEFT OUTER JOIN package_types AS package1 ON shipping_info.package_type = package_types.packageType_id

LEFT OUTER JOIN customer_info AS customer1 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

ORDER BY shipping_info.order_date DESC";

Fatal error: Call to a member function fetchAll() on a non-object in....

解决方案

try changing your query to this:

SELECT s1.shipping_id,

s1.service,

p1.package_type,

c1.country fromCountry,

c2.country toCountry,

c3.country resiCountry,

c1.name

FROM shipping_info si

LEFT JOIN service_types s1 ON si.service_type = s1.serviceType_id

LEFT JOIN package_types p1 ON si.package_type = p1.packageType_id

LEFT JOIN customer_info c1 ON si.customer_id = c1.customer_id

LEFT JOIN countries c1 ON si.from_loc = c1.country_id

LEFT JOIN countries c2 ON si.to_loc= c2.country_id

LEFT JOIN countries c3 ON si.to_id = c3.country_id

ORDER BY si.order_date DESC;

you had multiple typos in the query itself with incorrect syntax.. also LEFT OUTER JOIN and LEFT JOIN are exactly the same

Also can you post how you are executing this query? you may have an issue with the actual method for executing it.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值