find last instance of character in string mysql 1

find last instance of character in string mysql

SELECT SUBSTRING_INDEX("first_middle_last", '_', -1);

Here is what the above code is Doing:
1. We’re using the SUBSTRING_INDEX function to find the last occurrence of the underscore character in the string.
2. We’re using the SUBSTRING_INDEX function to find the first occurrence of the underscore character in the string.
3. We’re using the SUBSTRING function to extract the middle name from the string.

Similar Posts