update mos_akocomment set contentid = '20' where contentid = '31';
update mos_akocomment set contentid = '73' where contentid = '93';
update mos_akocomment set contentid = '199' where contentid = '200';
now these statements execute fine, however can someone tell me that what will be the format of this query If I want to write it in the different way so that I call update mos_akocomment only once (i.e. in the format in which you have the phpmyadmin exports)
1 you don’t need to quote numeric values as you keep doing (unless they are varchar/char field),
2 you should have an else condition otherwise if you have a value in the table for contentid that isn’t in that list, let’s say 96 for example, that row will have contentid set to NULL for that row. Your update should be:
UPDATE mos_akocomment
SET contentid= CASE
WHEN contentid = 20 THEN 31
WHEN contentid = 73 THEN 93
WHEN contentid = 199 THEN 200
WHEN contentid = 165 THEN 204
WHEN contentid = 79 THEN63
WHEN contentid = 71THEN 82
WHEN contentid = 6 THEN 17
WHEN contentid = 62 THEN 80
WHEN contentid = 132 THEN 126
[B]ELSE contentid[/B]
END
which says basically if the contentid in a row doesn’t match one of the conditions, leave it alone or update it to the existing value.
yes, It worked
1st I had run the sample posted above and it had zeroed all conetedid rows that did not match
it worked when I ran the complete query, there was no case of the condition not matching
UPDATE mos_akocomment
SET contentid= CASE
WHEN contentid = ‘20’ THEN ‘31’
WHEN contentid = ‘73’ THEN ‘93’
WHEN contentid = ‘199’ THEN ‘200’
WHEN contentid = ‘165’ THEN ‘204’
WHEN contentid = ‘79’ THEN’63’
WHEN contentid = '71’THEN ‘82’
WHEN contentid = ‘6’ THEN ‘17’
WHEN contentid = ‘62’ THEN ‘80’
WHEN contentid = ‘132’ THEN ‘126’
END
finally I migrated 2K comments from a 6 year old Mambo to shinny new wordpress