Skip to main content
GameDev.net gamedev.net
🔒 Locked

Seemingly simple mysql question *solved*

Started by Daniel Miller Jan 8, 2007 at 11:33 AM 3 replies 450+ views
Original Post
Daniel Miller
Daniel Miller
Let's say I have a table, and I want to change all instances of the string 'a' in column 'x' to 'b'. In other words, column x: abcdefa -> would become bbcdefb zzazzba -> would become zzbzzbb It seems simple, but I really have no idea how to do this! Any tips? This isn't from PHP, but I suppose I could use PHP. edit: I know that I will need to use the REPLACE function, but I don't know where to squeeze it in. edit: Solved, found the answer here: linky
Kylotan
Kylotan
No you don't. This is a job for UPDATE, not REPLACE.

UPDATE tablename SET x = bbcdefb WHERE x = abcdefa;
etc.
Daniel Miller
Daniel Miller
Quote:
Original post by Kylotan
No you don't. This is a job for UPDATE, not REPLACE.

UPDATE tablename SET x = bbcdefb WHERE x = abcdefa;
etc.


REPLACE was what I needed, because I was replacing 'a' in all instances of a string in each collumn, and it might appear more than once in one entry.
Excors
Excors
Seems like there's potential for confusion between the (MySQL-specific) REPLACE statement and the (standard?) REPLACE function - presumably it's the latter you're using (as in "UPDATE tablename SET x = REPLACE(x, 'a', 'b')"), which is a sensible way to do it.
Kylotan
Kylotan
My mistake; it wasn't immediately clear to me what you meant with the original post, but I get it now. Sorry!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.