How MySQL SUBSTRING_INDEX() function returns the substring if we provide the negative value of the argument ‘count’?

MySQLMySQLi Database

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)
raja
Published on 20-Feb-2018 12:31:57
Advertisements