If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Removing a Part of Text from Database Field

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-19-11, 02:01
akrashdi akrashdi is offline
Registered User
 
Join Date: Jul 2011
Posts: 8
Removing a Part of Text from Database Field

Hi,

I have the following in a field, which appears in many records:

common-words/someword

I wanna to change this to

expressions/someword

How should I write the SQL query for this.

Appreciated...
Reply With Quote
  #2 (permalink)  
Old 09-19-11, 06:04
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
UPDATE daTable
   SET afield = REPLACE(afield,'common-words/someword','expressions/someword')
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-19-11, 15:46
akrashdi akrashdi is offline
Registered User
 
Join Date: Jul 2011
Posts: 8
hmmm.....

Actually 'someword' means there are many records of different words in the table, i.e.

common-words/mufassir
common-words/muhaddith
common-words/faqiih
common-words/muhaqqiq
....

I wanna to change all these records to, lets say:

expressions/mufassir
expressions/muhaddith
expressions/faqiih
expressions/muhaqqiq
Reply With Quote
  #4 (permalink)  
Old 09-19-11, 15:50
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
UPDATE daTable
   SET afield = REPLACE(afield,'common-words/','expressions/')
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 09-19-11, 19:30
akrashdi akrashdi is offline
Registered User
 
Join Date: Jul 2011
Posts: 8
Oops.. there is a REPLACE function for that, I need to get some proper training for SQL.


Thanks.
Reply With Quote
  #6 (permalink)  
Old 09-20-11, 03:16
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
well its either that or look at da manuel
or possibly both
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On