Click to See Complete Forum and Search --> : deleting some text from the begin of a value


asmith20002
01-14-2009, 01:30 PM
Hi,

I wanted to know if there's someway I could do it without php.

I have this values in the table :

www.example.com/john
www.example.com/tom
www.example.com/jack


I wanna cut the "www.example.com/" from all of them, and they all have this at the beginning.

Is it possible I do it with a query?
Thanks

p.s If yea, Is it possible to do same thing if the string were in different parts , like beginning, middle, end...

talldean
01-14-2009, 02:45 PM
It should be possible, but I think it would be database specific.

In Microsoft's T-SQL, you could use REPLACE or SUBSTRING, for example.

What are you using?

asmith20002
01-14-2009, 03:14 PM
MySQL 5

talldean
01-14-2009, 04:05 PM
Taking a look at the string functions in MYSQL 5:
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html

SELECT REPLACE(FIELDNAME, 'www.example.com', '');

should return the column FIELDNAME, and replace every instance of www.example.com with an empty string.

asmith20002
01-15-2009, 01:12 AM
Thanks for the hint man, I found it ^^


update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, 'find this string', 'replace found string with this string');