下面的SQL语句曾经在几年前工作,现在它没有,我收到此错误消息:
1054 - 'on clause'中的未知栏'Promotion_Card_details.Card_id'
这是我的SQL语句:
SELECT DISTINCT Promotion_Card_details.Card_id,
Promotion_Merchant_details.Merchant_id,
Promotion_details.Promotion_id,
Issuer_details.IssuerName,
Card_details.CCType,
PaymentType_details.PaymentTypeName,
Merchant_details.MerchantName,
PromotionText,
PromotionEndDate
FROM Promotion_details
INNER JOIN Card_details ON (Card_details.Card_id=Promotion_Card_details.Card_id)
INNER JOIN Issuer_details ON (Issuer_details.Issuer_id=Card_details.Issuer_id)
INNER JOIN PaymentType_details ON (PaymentType_details.PaymentType_id=Card_details.PaymentType_id)
INNER JOIN Merchant_details ON (Merchant_details.Merchant_id=Promotion_Merchant_details.Merchant_id)
INNER JOIN Promotion_Merchant_details ON (Promotion_Merchant_details.Promotion_id=Promotion_details.Promotion_id)
INNER JOIN Promotion_Card_details ON (Promotion_details.Promotion_id=Promotion_Card_details.Promotion_id)
WHERE ((Promotion_details.Promotion_id = '13' OR Promotion_details.Promotion_id = '14'
OR
Promotion_details.Promotion_id = '15' OR Promotion_details.Promotion_id = '16' OR
Promotion_details.Promotion_id = '17' OR Promotion_details.Promotion_id = '18' OR
Promotion_details.Promotion_id = '19' OR Promotion_details.Promotion_id = '20' OR
Promotion_details.Promotion_id = '21' OR Promotion_details.Promotion_id = '22' OR
Promotion_details.Promotion_id = '23' OR Promotion_details.Promotion_id = '24' OR
Promotion_details.Promotion_id = '25' OR Promotion_details.Promotion_id = '361'
OR Promotion_details.Promotion_id = '364' OR Promotion_details.Promotion_id = '382') )
任何帮助都会非常感激,因为我在某些部分尝试了括号,但它仍然没有修复它。
答案 0 :(得分:11)
JOIN
是左关联的,因此给定的ON
子句只能引用已经提到的表。所以,重新排序这些:
FROM Promotion_details
INNER JOIN Card_details ON (Card_details.Card_id=Promotion_Card_details.Card_id)
INNER JOIN Issuer_details ON (Issuer_details.Issuer_id=Card_details.Issuer_id)
INNER JOIN PaymentType_details ON (PaymentType_details.PaymentType_id=Card_details.PaymentType_id)
INNER JOIN Merchant_details ON (Merchant_details.Merchant_id=Promotion_Merchant_details.Merchant_id)
INNER JOIN Promotion_Merchant_details ON (Promotion_Merchant_details.Promotion_id=Promotion_details.Promotion_id)
INNER JOIN Promotion_Card_details ON (Promotion_details.Promotion_id=Promotion_Card_details.Promotion_id)
按此顺序:
FROM Promotion_details
INNER JOIN Promotion_Card_details ON (Promotion_details.Promotion_id=Promotion_Card_details.Promotion_id)
INNER JOIN Card_details ON (Card_details.Card_id=Promotion_Card_details.Card_id)
INNER JOIN Issuer_details ON (Issuer_details.Issuer_id=Card_details.Issuer_id)
INNER JOIN PaymentType_details ON (PaymentType_details.PaymentType_id=Card_details.PaymentType_id)
INNER JOIN Promotion_Merchant_details ON (Promotion_Merchant_details.Promotion_id=Promotion_details.Promotion_id)
INNER JOIN Merchant_details ON (Merchant_details.Merchant_id=Promotion_Merchant_details.Merchant_id)