Monday 16 July 2018

MySQL FIELD() Function

MySQL FIELD() Function

Example

Return the position of the "c" value in the list of values:
SELECT FIELD("c""a""b""c""d""e");

Definition and Usage

The FIELD() function returns the position of a value in a list of values (val1, val2, val3, etc.).
Note: If all arguments in this function are string values, the find is performed as string values. If all arguments in this function are numeric values, the find is performed as numeric values.
Note: If 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(valueval1val2val3, ...)

Parameter Values

ParameterDescription
valueRequired. The value to find in the list
val1val2val3, ....Required. The list of values to search for

Technical Details

Works in:MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

More Examples

Example

Return the position of the "c" value in the list of values:
SELECT FIELD("c""a""b");

Example

Return the position of the "D" value in the list of values:
SELECT FIELD("D""a""b""c""d""e");

0 comments:

Post a Comment