Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous table Update query

Tags:

sql

sql-server

I am getting the error message "table is ambiguous. I am using aliases so unsure why the table is ambiguous. Here is my code:

UPDATE Field_Translations
    SET SourceColumn1='EnteredProduct'
        ,SourceValue1=I.Product
        ,TargetColumn1='NewProduct'
        ,TargetValue1='Not Reported'
        ,TargetColumn2='NewProductId'
        ,TargetValue2=-1
    FROM Org8_28_17 I
        LEFT JOIN Field_Translations FT ON I.Vendor=FT.SourceValue1 AND FT.SourceColumn1='HGVendor'
        LEFT JOIN Field_Translations FT2 ON I.Product=FT2.SourceValue1 AND FT2.SourceColumn1='HGProduct' 
    WHERE FT.TargetValue1 IS NOT NULL AND FT2.TargetValue1 IS NULL --AND I.Product like '%(%'
        AND I.Vendor=I.Product AND I.Vendor=FT.TargetValue1
like image 463
user7577070 Avatar asked Dec 19 '22 04:12

user7577070


1 Answers

If you alias the table name in the FROM clause, you must use the alias in the UPDATE clause:

UPDATE FT

Not

UPDATE Field_Translations

Your use of Field_Translations is ambiguous because you have joined to it twice.

like image 154
Tab Alleman Avatar answered Jan 01 '23 16:01

Tab Alleman