Retrieve the index position of “q” within the given list of strings.
| SELECT FIELD(“q”, “s”, “q”, “l”); |
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.
| FIELD(value, val1, val2, val3, …) |
|
Parameter |
Description |
|
value |
Necessary: The value to be searched for within the list. |
|
val1, val2, val3, …. |
Necessary: The list of values to be searched within. |
| Works in: | From MySQL 4.0 |
Retrieve the index position of “c” within the given list of strings.
| SELECT FIELD(“c”, “a”, “b”); |
Retrieve the index position of “Q” within the provided list of strings.
| SELECT FIELD(“Q”, “s”, “q”, “l”); |
Retrieve the index position of the number 5 within the given list of numbers.
| SELECT FIELD(5, 0, 1, 2, 3, 4, 5); |