Update common column across multiple tables
Posted: Tue Mar 22, 2011 12:25 pm
Is there a way to combine the following queries into a single multi-table update, and if so, would it be faster? There are 24 tables with the 'user' column, and every one needs to be updated as follows (where 2 and 3 are dupes of 1 and so need to be merged). With 4,000 sets of dupes I have close to 100,000 queries to run as it's set now (with another 100,000 merging different tables for the same reason). It's taking a very long time to run on our test server. Thanks ahead of time.
Code: Select all
UPDATE table1 SET user = 1 WHERE user IN (2,3);
UPDATE table2 SET user = 1 WHERE user IN (2,3);
UPDATE table3 SET user = 1 WHERE user IN (2,3);
...