I'm attempting to replace particular text strings in multiple tables and fields. I have code to do it for one field in one table, but I don't want to duplicate my efforts (since I have many strings I'd like to replace).
Here's my code for one field in one table:
UPDATE `phpbb3`.`phpbb_posts`
SET `post_subject` = REPLACE(`post_subject`,'string-to-be-replaced','replacement-string')
WHERE ( `post_subject` LIKE '%string-to-be-replaced%' )
ORDER BY `phpbb_posts`.`post_time` DESC
How do I write a command to replace text in both the phpbb_posts.post_subject field and the phpbb_topics.topic_title field?
(Do I need the WHERE or ORDER, since phpMyAdmin doesn't show the results of an UPDATE anyway?)
ORDER BYclause, but I'm not sure why you wouldn't need to use aWHEREclause because of phpMyAdmin.UPDATEqueries without aWHEREclause affect all rows in the table, so they're generally a bad idea. In this specific instance it may not matter much, because MySQL will be using thereplacefunction to look forstring-to-be-replacedand only replace this in any matching rows. But generally, aWHEREclause is the most important thing of anUPDATEquery. You don't want all of your users' passwords to be changed because one user changed his password.