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


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)

Monica Mona
Monica Mona

Student of life, and a lifelong learner

Updated on: 20-Jun-2020

505 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements