0

Trying to run this query and it keeps on telling me ambiguous column name on VendorID need help

Select VendorID
     , VendorName
     , InvoiceNumber
     , InvoiceDate
     , InvoiceTotal 
  FROM Vendors
  JOIN Invoices
    ON Vendors.VendorID = Invoices.InvoiceID
Strawberry
  • 33,750
  • 13
  • 40
  • 57

1 Answers1

2

Just qualify all your column names, and you will never have this problem again. I also think your ON conditions are wrong:

SELECT v.VendorID, v.VendorName, i.InvoiceNumber, i.InvoiceDate, i.InvoiceTotal
FROM Vendors v JOIN
     Invoices i
     ON v.VendorID = i.VendorID;
-----------------------^

For completeness, I will note that you can fix this particular problem with the USING clause. However, it is better just to write code defensively so queries don't generate errors.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786