ID EN
String Functions and Operators

FIELD(str,str1,str2,str3,...)

MySQL 8.4

Returns the index (position) of str in the str1, str2, str3, ... list. Returns 0 if str is not found.

Syntax

MYSQL
SELECT FIELD('Bb', 'Aa', 'Bb', 'Cc', 'Dd', 'Ff');
2
SELECT FIELD('Gg', 'Aa', 'Bb', 'Cc', 'Dd', 'Ff');
0

Examples

Example

If all arguments to FIELD() are strings, all arguments are compared as strings. If all arguments are numbers, they are compared as numbers. Otherwise, the arguments are compared as double.

MYSQL
SELECT FIELD('Bb', 'Aa', 'Bb', 'Cc', 'Dd', 'Ff');
2
SELECT FIELD('Gg', 'Aa', 'Bb', 'Cc', 'Dd', 'Ff');
0