How MySQL SUBSTRING_INDEX() function returns the substring if we provide the negative value of the 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: 10-Feb-2020

274 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements