0

I have a table in a MySQL database that features a 'name' column with values such as:

  • SDP3973455/1
  • 101390375/2
  • SDP4608677
  • 105859492/1
  • 104295947

As you can see, some values have the characters 'SPD' in front and some values have '/1 or /2' at the end of the string. I want to keep only the numbers inbetween these characters. So 'SDP3973455/1' would be replaced with '3973455' and '105859492/1' would be replaced with '105859492'.

I have tried using the following query but I get this message '0 row(s) affected Rows matched: 2171368 Changed: 0 Warnings: 0':

UPDATE myTable
SET name = REPLACE(name, 'SDP', '');

If anybody can point me in the right direction that would be very much appreciated. Also if you can figure out how to delete '/1' or '/2' that would be wonderful.

3
  • It either SDP or SPD. Please correct where appropriate. Commented Jan 4, 2021 at 22:57
  • If your MySQL is version 8 (or up) consider using regular expressions. Commented Jan 4, 2021 at 23:00
  • Try escaping name with backticks since it is a MySQL keyword. Commented Jan 5, 2021 at 1:23

1 Answer 1

1

That would suggest that your column has no 'SPD' in it.

One problem might be intervening characters. Presumably, this query returns no rows:

select t.*
from myTable t
where name like '%SPD%';

You could then try a more general pattern:

select t.*
from myTable t
where name like '%S%P%D%';

Or perhaps the characters are from an extended character set.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.