Inner Joining the same table multiple times

前端 未结 5 800
感情败类
感情败类 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:32

    You need a different alias for the table each time you use it.

    SELECT B.BlankTypeCode, B.BlankCode, A1.Amount, A1.Type, P1.PurchaseDate, P1.DatePaid
      FROM Blank AS B
      JOIN Ticket    AS T  ON B.BlankCode = T.Blank_BlankCode
      JOIN MCO_Blank AS M  ON B.BlankCode = M.Blank_BlankCode
      JOIN Purchase  AS P1 ON T.PurchaseID = P1.PurchaseID
      JOIN Purchase  AS P2 ON M.PurchaseID = P2.PurchaseID
      JOIN Payment   AS A1 ON T.PurchaseID = A1.PurchaseID
      JOIN Payment   AS A2 ON M.PurchaseID = A2.PurchaseID
     WHERE A1.Status = "Paid"
       AND A2.Status = "Paid"
    

    You'll need to sort out which versions of the Purchase and Payment tables the selected columns come from, and also what should be in the WHERE clause really.

提交回复
热议问题