MySQL query to update a field with data from another field when two fields match

I need to update the contents of one data field in a table with the contents of another field in the table every time two separate fields coincide, one on each table. I tried this syntax, but I just can't get it to work correctly without giving me an error.

UPDATE table1
   SET field1 = table2.field1
  FROM Table1,Table2
 WHERE Table1.entry = Table2.entry
+3
source share
1 answer

update ... fromis the syntax of the SQL server. In MySQL, you can simply use multiple tables directly:

update
  table1 t1
  join table2 t2 on t2.field = t1.field
set
  t1.field1 = t2.matchingfield
where
  t1.whatever = t2.whatever

Everything is described in detail on the MySQL help page .

+7
source

Source: https://habr.com/ru/post/1750803/


All Articles