Is this possible in mysql?
update table1
set column1 = (select column1 from table2
inner join table3
where table2.column5 = table3.column6);
Here is a a similar question for an Oracle DB.
The most easiest and common way is to use join clause in the update statement and use multiple tables in the update statement. Here we can see that using join clause in update statement. We have merged two tables by the use of join clause.
The MySQL Update Join is used for executing the update statement together with the implementation of INNER JOIN and LEFT JOIN MySQL clauses in the server. This Update JOIN clause in MySQL helps to retrieve the data records from the related database tables along with modifying them with the query.
It is possible to join two or more tables in an UPDATE query.
SQL UPDATE JOIN could be used to update one table using another table and join condition. UPDATE tablename INNER JOIN tablename ON tablename. columnname = tablename.
You can do it. However, in the example you give, there's no JOIN connection between table1 and the source of the values for the update (table2 INNER JOIN table3), so the results will be somewhat unpredictable.
Your query would be something like (I'm not a MySQL expert):
UPDATE table1, table2, table3 SET table1.column1 = table2.column1
WHERE table2.column5 = table3.column6
but what I think you probably want (I'm just guessing) is something more like:
UPDATE table1, table2, table3 SET table1.column1 = table2.column1
WHERE table1.somecolumn = table3.somecolumn AND table2.column5 = table3.column6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With