MySQL FIND_IN_SET() Function
In MySQL, the FIND_IN_SET() function return the position of a specified value in a comma-separated string list. It is similar to the FIELD() function.
FIND_IN_SET() Syntax
Here is the syntax of MySQL FIND_IN_SET() function:
FIND_IN_SET(string, string_list)
Parameter Description
string- Required. This is the string to search for.
string_list- Required. This is a comma-separated list of strings.
Return value
- If
string_listincludesstring, the function will return the corresponding position number. - If
string_listdoes not includestring, the function will return0. - If
stringisNULL, the function will returnNULL. - If
string_listis an empty string, the function will return0. - If
string_listisNULL, the function will returnNULL.
FIND_IN_SET() Examples
SELECT
FIND_IN_SET('A', 'A,B,C'),
FIND_IN_SET('D', 'A,B,C'),
FIND_IN_SET('D', ''),
FIND_IN_SET(NULL, 'A,B,C'),
FIND_IN_SET('D', NULL)\G
FIND_IN_SET('A', 'A,B,C'): 1
FIND_IN_SET('D', 'A,B,C'): 0
FIND_IN_SET('D', ''): 0
FIND_IN_SET(NULL, 'A,B,C'): NULL
FIND_IN_SET('D', NULL): NULL
1 row in set (0.00 sec)