42

I want to delete part of a string found in a particular field.

For example, the entry in the field could be "01365320APS". The "APS" is what I am looking at deleting.

My question is, should I use:

SELECT SUBSTRING_INDEX('fieldname','APS', 1)
tumultous_rooster
  • 12,150
  • 32
  • 92
  • 149
Mike Jones
  • 579
  • 1
  • 9
  • 15

2 Answers2

117

When you want to edit a field, you need an UPDATE statement:

UPDATE table SET fieldname=REPLACE(fieldname,'APS','')

REPLACE is a string function that replaces every occurence of the 2nd string in the 1st string with the 3rd one.

Please try this with a WHERE clause first, to see if it is really what you want to do.

Jacob
  • 41,721
  • 6
  • 79
  • 81
16

For every occurrence of APS, try this:

UPDATE table SET column=REPLACE(column,'APS','');

Reference: http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_replace

AJ.
  • 27,586
  • 18
  • 84
  • 94