开发者

SQL Inner join 2 tables with multiple column conditions and update

开发者 https://www.devze.com 2023-01-05 13:41 出处:网络
I am using this script, trying to join 2 tables with 3 conditions and update T1: Update T1 set T1.Inci = T2.Inci

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 
A开发者_运维问答ND T1.Category= T2.Category
AND T1.Date = T2.Date

but I encounter:

Incorrect syntax near the keyword 'ON'.

Can't figure it out why.


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


You need to do

Update table_xpto
set column_xpto = x.xpto_New
    ,column2 = x.column2New
from table_xpto xpto
   inner join table_xptoNew xptoNew ON xpto.bla = xptoNew.Bla
where <clause where>

If you need a better answer, you can give us more information :)


UPDATE T1,T2 
INNER JOIN T1 ON  T1.Brands = T2.Brands
SET 
T1.Inci = T2.Inci
WHERE
    T1.Category= T2.Category
AND
    T1.Date = T2.Date


You should join T1 and T2 tables using sql joins in order to analyze from two tables. Link for learn joins : https://www.w3schools.com/sql/sql_join.asp

0

精彩评论

暂无评论...
验证码 换一张
取 消