In MySQL, which function we can use to find the index position of a particular string from a list of strings?

MySQLMySQLi Database

We can use FIELD() function to find the index position of a particular string from a list of strings.

Syntax

FIELD(str search,String1, String2,…StringN)

Here, the str search is the string whose index number we want to search and String1, String …StringN is the list of strings from which the search would happen.

Example

mysql> Select FIELD('good', 'Ram', 'is', 'a', 'good', 'boy')AS 'Index Number of good';
+----------------------+
| Index Number of good |
+----------------------+
|                  4   |
+----------------------+
1 row in set (0.00 sec)
raja
Published on 20-Feb-2018 10:28:11
Advertisements