Query error with ambiguous column name in SQL

前端 未结 8 817
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 06:54

I get an Ambiguous column name error with this query (InvoiceID). I can\'t figure out why. They all seem to be joined correctly so why doesn\'t the management studio know to

8条回答
  •  广开言路
    2020-11-27 07:54

    One of your tables has the same column name's which brings a confusion in the query as to which columns of the tables are you referring to. Copy this code and run it.

    SELECT 
        v.VendorName, i.InvoiceID, iL.InvoiceSequence, iL.InvoiceLineItemAmount
    FROM Vendors AS v
    JOIN Invoices AS i ON (v.VendorID = .VendorID)
    JOIN InvoiceLineItems AS iL ON (i.InvoiceID = iL.InvoiceID)
    WHERE  
        I.InvoiceID IN
            (SELECT iL.InvoiceSequence 
             FROM InvoiceLineItems
             WHERE iL.InvoiceSequence > 1)
    ORDER BY 
        V.VendorName, i.InvoiceID, iL.InvoiceSequence, iL.InvoiceLineItemAmount
    

提交回复
热议问题