Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 906
marilyn Avatar asked Jul 01 '10 08:07

marilyn


People also ask

Can you inner join on multiple columns?

Yes: You can use Inner Join to join on multiple columns.

How do I join two tables with different column names in SQL?

Merging tables by columns. Multiple tables can be merged by columns in SQL using joins. Joins merge two tables based on the specified columns (generally, the primary key of one table and a foreign key of the other).


2 Answers

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 
like image 166
Robin Day Avatar answered Sep 22 '22 12:09

Robin Day


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 :)

like image 44
Bruno Costa Avatar answered Sep 21 '22 12:09

Bruno Costa