6

I need to remove the last part of a string in a column where I have a field named "path" that looks like:

images/prop/images/2034/22399_2034.JPG

I need everything after the last "/" to be deleted, in order to have

images/prop/images/2034/

instead of

images/prop/images/2034/22399_2034.JPG

I have no idea if this is possible. Thanks.

fooquency
  • 1,575
  • 3
  • 16
  • 29
ol30cean0
  • 481
  • 4
  • 8
  • 18

1 Answers1

14

You can combine MySQL's TRIM() and SUBSTRING_INDEX() functions:

SELECT TRIM(TRAILING SUBSTRING_INDEX(path, '/', -1) FROM path)
FROM   my_table

See it on sqlfiddle.

eggyal
  • 122,705
  • 18
  • 212
  • 237