1054 Full Join中的未知列,但不是其他连接

时间:2014-10-28 17:16:57

标签: php mysql join

为什么我会收到" 1054未知列错误"来自以下mysql语法:

SELECT attorney_first_name, attorney_last_name, att_school, att_degree_obtained
FROM jos_legalally_attorneys
FULL JOIN jos_legalally_attorney_education
ON jos_legalally_attorneys.user_id=jos_legalally_attorney_education.user_id;

导致错误:

#1054 - Unknown column 'jos_legalally_attorneys.user_id' in 'on clause' 

尝试FULL JOIN时,我只收到此错误消息。使用此精确语法时,所有其他连接(内部,右侧,左侧)都是成功的。 (我尝试了FULL OUTER JOIN变体)。

1 个答案:

答案 0 :(得分:3)

报告here,MySQL不支持FULL JOIN,因此您的查询解释如下:

SELECT attorney_first_name, attorney_last_name, att_school, att_degree_obtained
FROM jos_legalally_attorneys as FULL #FULL is taken as table alias!!
INNER JOIN jos_legalally_attorney_education
ON jos_legalally_attorneys.user_id=jos_legalally_attorney_education.user_id;

现在,由于它FULL的表格别名为jos_legalally_attorneys,因此无法正常使用。

如果你尝试以下查询,它应该没有错误(即使它没有做你想要的):

SELECT attorney_first_name, attorney_last_name, att_school, att_degree_obtained
FROM jos_legalally_attorneys
FULL JOIN jos_legalally_attorney_education
ON FULL.user_id=jos_legalally_attorney_education.user_id;

现在,为了获得MySQL所需的FULL JOIN,你需要做这样的事情(如图here所示):

SELECT attorney_first_name, attorney_last_name, att_school, att_degree_obtained
FROM jos_legalally_attorneys
LEFT JOIN jos_legalally_attorney_education
ON jos_legalally_attorneys.user_id=jos_legalally_attorney_education.user_id
UNION ALL
SELECT attorney_first_name, attorney_last_name, att_school, att_degree_obtained
FROM jos_legalally_attorneys
RIGHT JOIN jos_legalally_attorney_education
ON jos_legalally_attorneys.user_id=jos_legalally_attorney_education.user_id