FIELD
FIELD(str,str1,str2,str3,…)
Section titled “FIELD(str,str1,str2,str3,…)”- str: This parameter is the string to be compared. It is the value that the function is searching for within the subsequent parameters.
- str1, str2, str3,…: These parameters are the set of strings where “str” is being searched for. The function returns the index (position) of the first occurrence of “str” in this list. If “str” is not found, the function returns 0. Multiple strings can be provided.
Example
Section titled “Example”SELECT FIELD('MySQL', 'Oracle', 'SQL Server', 'MySQL', 'MongoDB');Output
Section titled “Output”3Explanation
Section titled “Explanation”The FIELD function in MySQL returns the index (position) of a string within a list of strings. It returns 0 if the string is not found. In the provided example, ‘MySQL’ is the third string in the list, so the output is 3.