bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL References
SQL•SQL References

MySQL FIELD() Function

Concept visual

MySQL FIELD() Function

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

Example

Return the index position of "q" in the string list:

SELECT FIELD("q", "s", "q", "l");

Definition and Usage

The FIELD() function returns the index position of a value in a list of values.

Formula

This function performs a case - insensitive search.

Note:

If the specified value is not found in the list of values, this function will return 0. If value is NULL, this function will return 0.

Syntax

Field(

value, val1, val2, val3, ...)

Parameter Values

Parameter

Description value

Required. The value to search for in the list val1, val2, val3, .... Required. The list of values to search

Technical Details

Works in:

From MySQL 4.0

More Examples

Example

Return the index position of "c" in the string list:

SELECT FIELD("c", "a", "b");

Example

Return the index position of "Q" in the string list:

SELECT FIELD("Q", "s", "q", "l");

Example

Return the index position of 5 in the numeric list:

SELECT FIELD(5, 0, 1, 2, 3, 4, 5);

Previous

❮ MySQL Functions

Next

Previous

MySQL CONCAT_WS() Function

Next

MySQL FIND_IN_SET() Function