错误代码:1066。不是唯一的表/别名:'文件'

时间:2016-05-03 08:46:12

标签: mysql

我正在使用MySQL而我正在尝试从两个表中加入列并执行此查询

我正在尝试安排像这样的列

  • Transaction.TransactionID
  • Transaction.TransactionDate
  • Transaction.Amount
  • TransactionDescription.Description
  • File.StartDate
  • File.EndDate
  • File.FileName

    SELECT Transaction.TransactionID,Transaction.TransactionDate,Transaction.Amount,TransactionDescription.Description ,File.StartDate,File.EndDate,File.Filename 来自交易 INNER JOIN TransactionDescription ON TransactionDescription.Description = TransactionDescription.Description INNER JOIN文件ON File.StartDate = File.StartDate INNER JOIN文件ON File.EndDate = File.EndDate INNER JOIN文件ON File.Filename = File.Filename ; 但是当执行查询时,我收到此错误

    错误代码:1066。不是唯一的表/别名:'文件' 为什么会出现错误?

1 个答案:

答案 0 :(得分:0)

由于查询中有三个File表,因此当您说File时,MySQL无法知道您的意思。您通常会修复分配不同表别名的问题。但实际上你需要连续三次加入同一个桌子感觉相当奇怪。我的印象是你只需要一次,如:

SELECT Transaction.TransactionID, Transaction.TransactionDate, Transaction.Amount, TransactionDescription.Description
,File.StartDate, File.EndDate, File.Filename
FROM Transaction
INNER JOIN TransactionDescription ON  TransactionDescription.Description = TransactionDescription.Description
INNER JOIN File ON  File.StartDate = File.StartDate
    AND File.EndDate = File.EndDate
    AND File.Filename = File.Filename