-2

I want to use update for any record and all records of my table that column1 <> column2 my command is :

update table1 set name = (select name from table2
                           where code1 <> code2 and table1.id=table2.id)

Is it possible?

And is it possible to use inner join in update command?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Ehsan Pakravan
  • 91
  • 1
  • 1
  • 3

1 Answers1

1

You can simply join both tables,

UPDATE  a
SET     a.Name = b.Name
FROM    Table1 a
        INNER JOIN Table2 b
            ON a.ID = b.id
WHERE   a.Code1 <> a.Code2
John Woo
  • 258,903
  • 69
  • 498
  • 492