According to the documentation :
SUBSTRING_INDEX(str,delim,count)
Returns the substring from str before counting delim delimiter attachments. If the counter is positive, everything is returned to the left of the trailing separator (counting from the left). If the counter is negative, everything that is to the right of the final separator (counting to the right) is returned. SUBSTRING_INDEX () is case-sensitive when looking for a delimiter.
In your example str is "STACK \ HYUUM.ROOOO". Be careful with '\', this must be escaped because it is a special character. To do this, replace '\' with '\\'. delim is '\\' (shielded too), and count is -1 because you want the right side of delim.
Example:
mysql> SELECT * FROM foo; +-------------------+ | name | +-------------------+ | STACK\HYUUM.ROOOO | +-------------------+ 1 row in set (0.00 sec)
Then
mysql> SELECT SUBSTRING_INDEX(name, '\\', -1) AS foo FROM foo; +-------------+ | foo | +-------------+ | HYUUM.ROOOO | +-------------+ 1 row in set (0.00 sec)
Or, a simpler example:
SELECT SUBSTRING_INDEX('STACK\\HYUUM.ROOOO', '\\', -1);
Remember to avoid the backslash in 'STACK \ HYUUM.ROOOO'.
source share