If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > UPDATE method in MYSQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-15-04, 16:08
tdnetworks tdnetworks is offline
Registered User
 
Join Date: Sep 2004
Posts: 1
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?
Reply With Quote
  #2 (permalink)  
Old 09-16-04, 05:21
RBARAER RBARAER is offline
Registered User
 
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 05:24.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On