Hello Bob,

----- Original Message -----
From: "Bob Loeffler" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, November 26, 2003 10:01 AM
Subject: Replacing text using the Update command?


> Hi all!
>
> I would like to update many records in a table called "pictures" where I
> find a string in the "caption" column.  If the string (e.g. "www.bob.com")
> is found, replace it with another string (e.g. "www.bubba.com").
> Unfortunately, there is other text in the caption column of these records,
> so I can't just do a simple update.  How can I replace a string of text
> within a column without destroying the other text in that column?  For my
> example, here is a command to find all records with the text string that
I'm
> looking for:
>
> select id from pictures where caption like '%www.bob.com%';
>
> Now I want to replace the string "www.bob.com" in those records with
> "www.bubba.com". One of the records has the following in the caption
column:
>
> "There is a party at www.bob.com"
>
> Now I want it to be:
>
> "There is a party at www.bubba.com"
>
> I'm sure there is an easy way to do this.   :-)

update pictures set caption=REPLACE(caption,"www.bob.com",www.bubba.com);

MySQL's update optimisation should automatically save it from updating those
rows that do not need to change.

Stephen


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to