Curriculum
Course: MYSQL
Login

Curriculum

MYSQL

MySQL References

0/140
Text lesson

FIELD

Example

Retrieve the index position of “q” within the given list of strings.

SELECT FIELD(“q”“s”“q”“l”);  

Definition and Usage

The FIELD() function retrieves the index position of a value within a list of values, performing a case-insensitive search.

Note: If the specified value is not found or is NULL, the function returns 0.

Syntax

FIELD(valueval1val2val3, …)

Parameter Values

Parameter

Description

value

Necessary: The value to be searched for within the list.

val1val2val3, ….

Necessary: The list of values to be searched within.

Technical Details

Works in: From MySQL 4.0

More Examples

Example

Retrieve the index position of “c” within the given list of strings.

SELECT FIELD(“c”“a”“b”);  

Example

Retrieve the index position of “Q” within the provided list of strings.

SELECT FIELD(“Q”“s”“q”“l”);  

Example

Retrieve the index position of the number 5 within the given list of numbers.

SELECT FIELD(50, 12, 345);