I'm trying to update every row of my invoices table to hold the tax amount of that invoice. This is calculated by getting the tax percentage associated with the vendor and multiplying it by the invoice amount (obviously). My problem is that I'm trying to update the table with data from the same table joined with others. Currently, my query shown below gives errors of:
Error Code: 1093. Table 'tblVendorInvoices' is specified twice, both as a target for 'UPDATE' and as a separate source for data
when I remove the WHERE
statement &
Error Code: 1054. Unknown column 'a.VENDORINVOICEID' in 'where clause'
With the WHERE
.
Here is my query:
UPDATE tblVendorInvoices SET VdrTaxAmount =
(SELECT round(VdrInvoiceAmount*TaxAmount,2) FROM tblVendorInvoices a
LEFT JOIN tblVendors ON a.VendorName = tblVendors.VendorID
LEFT JOIN tblTax on tblVendors.vdrtaxid = tblTax.TAXID)
WHERE a.VENDORINVOICEID = tblVendorInvoices.VENDORINVOICEID;