2017-05-04 76 views
0

我收到一個錯誤「未知列‘YahrzeitName’在‘關於條款’」試圖運行下面的查詢時:使用列別名與INNER 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 YahrzeitName = tbldecedent.Name 

回答

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