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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With