Hi. is there a way to return the first occurrence of a space from the right side of the string in sql ?
thanks! :)
Hi. is there a way to return the first occurrence of a space from the right side of the string in sql ?
thanks! :)
I think you are looking for something like SUBSTRING_INDEX
mysql> SELECT SUBSTRING_INDEX('first second end', ' ', -1);
+----------------------------------------------+
| SUBSTRING_INDEX('first second end', ' ', -1) |
+----------------------------------------------+
| end |
+----------------------------------------------+
1 row in set (0.00 sec)
Hmm, a brief browse through the function list didn't pop up any "search backwards" functions at me, but what you could do is reverse the string and search forwards:
SELECT LENGTH(`haystack`) - POSITION('needle' IN REVERSE(`haystack`))