MySQL SUBSTRING_INDEX() function can accept the negative value of argument ‘count’ and in this case, it returns the substring from the right of the final delimiter.
Example
mysql> Select SUBSTRING_INDEX('www.google.com','.',-2); +------------------------------------------+ | SUBSTRING_INDEX('www.google.com','.',-2) | +------------------------------------------+ | google.com | +------------------------------------------+ 1 row in set (0.00 sec) mysql> Select SUBSTRING_INDEX('www.google.com','.',-1); +------------------------------------------+ | SUBSTRING_INDEX('www.google.com','.',-1) | +------------------------------------------+ | com | +------------------------------------------+ 1 row in set (0.00 sec)