Find Index Position of a String in MySQL



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)
Updated on: 2020-06-20T08:41:52+05:30

658 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements