MySQL SUBSTRING_INDEX Function with Negative Argument Count



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)
Updated on: 2020-02-10T07:11:51+05:30

336 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements