使用LEFT OUTER JOIN连接多个表 [英] Connect multiple tables using LEFT OUTER JOIN

查看:996
本文介绍了使用LEFT OUTER JOIN连接多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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";

致命错误:在...中的非对象上调用成员函数fetchAll().

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

推荐答案

尝试将查询更改为此:

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;

您在查询中输入了多种错误的语法错误..LEFT OUTER JOIN和LEFT JOIN完全相同

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.

这篇关于使用LEFT OUTER JOIN连接多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆