Skip to content
Advertisement

How to Update new tables inside another update query?

I have a legacy system and i have a php file inside of it, updating one table. Now i added a new table to my db and i want to update that table too. The problem is that (for some reasons) i cannot use another query and i have to change the current query.

simplified former query: $q = "UPDATE t1 SET var=$var WHERE id=1";

I can’t use "UPDATE t1,t2 SET t1.var=$var t2.var=$var2 WHERE id=1" since it adds too much processing time. Is it possible to run two update queries in one query? I am using mysql commands in my entire system and i can’t change it to mysqli.

Advertisement

Answer

For anyone coming to this question, there are two simple ways to do this:

Method 1:

Method 2 (inner join):

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement