skip to Main Content

I have a table in phpMyadmin which is called Circuits with a column MCBs_id and i want to change the id 22 with id 19, the id 23 with id 20 and the id 24 with id 20.

How can i Run a script to change all at once with SQL query?

2

Answers


  1. then you need to do this :

    ;with cte as (
    select Id , MCBs_id 
    from yourtable 
    where MCBs_id in ( 22,23,24)
    )
    
    update t 
    Set MCBs_id = case cte.MCBs_id when 22 then 19 
                                   when 23 then 20
                                   when 24 then 20
    from yourtable t
    join cte 
     on t.Id = cte.Id
    
    Login or Signup to reply.
  2. This are the queries to update de value of field MCBs_id:

    UPDATE Circuits SET MCBs_id = 19 WHERE MCBs_id = 22;
    UPDATE Circuits SET MCBs_id = 20 WHERE MCBs_id = 23;
    UPDATE Circuits SET MCBs_id = 20 WHERE MCBs_id = 24;
    

    Consider that all the rows which meet the condition (WHERE) will be update in each of the queries.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search