0

Hi

I need to delete words before a set of words in a field.

eg delete the words before the word price in that field.

I already have a query to replace a certain word but cant see how adapt it to do what I require
update TABLE set field = replace(field,'price','');

can somebody help please?
Thanks in advance

2
Contributors
1
Reply
17
Views
3 Years
Discussion Span
Last Post by diafol
0

You'd probably need to do a regexp replacement, but MySQL doesn't have one. You could try this: https://github.com/hholzgra/mysql-udf-regexp

However you can use LOCATE() or POSITION() to find the position of a word and then you can trim the field using SUBSTRING():

Something like this...

UPDATE table1 SET field1 = IF(LOCATE('$TEXT',field1) > 0, SUBSTRING($field1, LOCATE('$TEXT', field1)), field1)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.