Jump to content


Replacing a Title

  • Please log in to reply
3 replies to this topic

#1 Orangize

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 July 2003 - 06:28 AM

I have this 1.1 MB MySQL database set up, and inside the table named lyrics, i have a column named artist. I want to remove all instances of \"The\" in the artist names. I\'ve read something on the web about using the REPLACE command, but I don\'t want to do it individually for each string since I have over 700 records. So I was wondering if you guys could help me out.

Thanks a bunch

#2 shivabharat

  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 22 July 2003 - 06:52 AM

You can try something like this

update <table_name> SET <filed_name> = (replace(<filed_name>,"string1","string2"));

Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#3 gizmola

  • Administrators
  • Advanced Member
  • 4,664 posts
  • LocationLos Angeles, CA USA

Posted 22 July 2003 - 08:38 AM

The sql standard way of doing this would be approximately this:

update lyrics
set artist = SUBSTRING(artist, 5)
where UPPER(artist) like \'THE %\';

Make sure you do a select first just to make sure that the substring replacement is working right:

select SUBSTRING(artist, 5)
from lyrics
where UPPER(artist) like \'THE %\';

#4 Orangize

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 July 2003 - 06:00 AM

Thank you so much for the help. It worked perfectly!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users