Inner Joining the same table multiple times

前端 未结 5 806
感情败类
感情败类 2020-12-20 19:35

So I have received this error: #1066 - Not unique table/alias: \'Purchase\'

I am trying to do the following:

    SELECT Blank.BlankTypeCode
              


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-20 20:14

    You need to use table aliases. You have mentioned the same table more than once in the from clause. The query is something like this:

    SELECT b.BlankTypeCode, b.BlankCode, pa1.Amount, pa1.Type, p1.PurchaseDate, pa2.DatePaid
    FROM Blank b
    INNER JOIN Ticket t
    ON b.BlankCode = t.Blank_BlankCode
    INNER JOIN MCO_Blank mb
    ON b.BlankCode = mb.Blank_BlankCode
    INNER JOIN Purchase p1
    ON  t.PurchaseID = p1.PurchaseID
    INNER JOIN Purchase p2
    ON mb.PurchaseID = p2.PurchaseID
    INNER JOIN Payment pa1
    ON t.PurchaseID = pa1.PurchaseID
    INNER JOIN Payment pa2
    ON mc.PurchaseID = pa2.PurchaseID
    WHERE pa1.Status = "Paid";
    

    I had to make a guess at which payment and purchase is intended for the aliases. These may not be correct in the from and where clauses.

提交回复
热议问题