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(value, val1, val2, val3, ...)
Parameter Values
Parameter | Description |
---|---|
value | Required. The value to find in the list |
val1, val2, val3, .... | 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