Search code examples
sqlsql-updateinner-join

SQL Inner join 2 tables with multiple column conditions and update


I am using this script, trying to join 2 tables with 3 conditions and update T1:

Update T1 set T1.Inci = T2.Inci 
ON T1.Brands = T2.Brands 
AND T1.Category= T2.Category
AND T1.Date = T2.Date

but I encounter:

Incorrect syntax near the keyword 'ON'.

Can't figure it out why.


Solution

  • UPDATE
        T1
    SET
        T1.Inci = T2.Inci 
    FROM
        T1
    INNER JOIN
        T2
    ON
        T1.Brands = T2.Brands
    AND
        T1.Category= T2.Category
    AND
        T1.Date = T2.Date