0

I have 5 table in a single database and same time of field name. the things i need to is bellow

UPDATE `customers` SET  `username`='new' WHERE `username`='old';
UPDATE `radacct` SET `username`='new' WHERE `username`='old';
UPDATE `radcheck` SET `username`='new' WHERE `username`='old';
UPDATE `radreply` SET `username`='new' WHERE `username`='old';
UPDATE `radusergroup` SET  `username`='new' WHERE `username`='old';

now how can i update all table in a single query? I have tried with

UPDATE `customers`,`radacct`,`radcheck`,`radreply`,`radusergroup` SET  `username`='new' WHERE `username`='old' 

but its giving me error

1052 - Column 'username' in field list is ambiguous

looking for solution

2
  • Just because those column identifiers have the same name doesn't mean you can refer to all of them at once. You still need to specify each column individually in your query: Commented Aug 7, 2016 at 17:46
  • 1
    try a multi query and does that column actually exist and in all tables? what you tried won't work btw. you need a multi query. Commented Aug 7, 2016 at 17:46

2 Answers 2

1

You can do this with help of join.

  UPDATE customers, 
           radacct, 
           radcheck,
           radreply,
           radusergroup  
    SET    customers.username = "new", 
           radacct.username = "new", 
           radcheck.username = "new"
           radreply.username = "new"    
           radusergroup.username = "new"
   WHERE   customers.username = "old"
            AND radacct.username = "old"
            AND radcheck.username = "old" 
            AND radreply.username = "old"  
            AND radusergroup.username = "old"
Sign up to request clarification or add additional context in comments.

Comments

0

If what you want is one call to query on php side, i would do:

$mysqli->query("UPDATE `customers` SET  `username`='new' WHERE `username`='old'; UPDATE `radacct` SET `username`='new' WHERE `username`='old'; UPDATE `radcheck` SET `username`='new' WHERE `username`='old'; UPDATE `radreply` SET `username`='new' WHERE `username`='old'; UPDATE `radusergroup` SET  `username`='new' WHERE `username`='old';");

If you want one query on mysql side, well since those table updates are not dependant from each other, i think there is no point as it makes a heavy query (as you can see on other answer).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.