使用INNER JOIN的列别名

时间:2017-05-04 01:40:43

标签: mysql

我收到错误"未知列' YahrzeitName'在' on条款'"尝试运行以下查询时:

SELECT 
concat(yahrzeit.firstName, ' ', yahrzeit.middleName, ' ', yahrzeit.lastName) 
AS 'YahrzeitName', 

concat(yahrzeit.gregorianYear, '-', yahrzeit.gregorianMonthNum, '-', yahrzeit.gregorianDay) 
AS Date,

tbldecedent.Name

FROM yahrzeit INNER JOIN tbldecedent 
ON YahrzeitName = tbldecedent.Name

1 个答案:

答案 0 :(得分:1)

您无法在join语句中使用列别名,请使用完整表达式替换别名:

SELECT 
    concat(yahrzeit.firstName, ' ', yahrzeit.middleName, ' ', yahrzeit.lastName) AS `YahrzeitName`,
    concat(yahrzeit.gregorianYear, '-', yahrzeit.gregorianMonthNum, '-', yahrzeit.gregorianDay) AS `Date`,
    tbldecedent.Name
FROM yahrzeit 
INNER JOIN tbldecedent
ON concat(yahrzeit.firstName, ' ', yahrzeit.middleName, ' ', yahrzeit.lastName) = tbldecedent.Name