SELECT SUBSTRING_INDEX(
SUBSTRING_INDEX('foo#bar#baz#qux', '#', 2), '#', -1
);
+----------------------------------------------------------------------+
| SUBSTRING_INDEX(SUBSTRING_INDEX('foo#bar#baz#qux', '#', 2), '#', -1) |
+----------------------------------------------------------------------+
| bar |
+----------------------------------------------------------------------+