Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2004
    Posts
    1

    Unanswered: UPDATE method in MYSQL

    Ok, here is a update statement I have...

    UPDATE support_test
    SET cat_id=42
    WHERE cat_id = 4

    It works fine, only thing is I need to update more numbers but I don't want to overwrite the updated numbers. Example, I want to update 42 to 6 but want to update the original 6's to 12. I have about 30+ numbers that need to be changed, any way to go about this?

  2. #2
    Join Date
    Aug 2004
    Location
    France
    Posts
    754
    Hello,

    I personnally would use another table (with the same structure as the first one). Instead of your updates, you would do :

    Insert into support_test_temp(cat_id, field2, field3) select 42, field2, field3 from support_test where support_test.cat_id=4;

    ... and so on for each change.

    Then :

    commit;

    delete from support_test;

    Insert into support_test select * from support_test_temp;

    commit;

    And finally get rid of the temp table :

    drop table support_test_temp;

    Regards,

    RBARAER
    Last edited by RBARAER; 09-16-04 at 06:24.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •