FIND_IN_SET
FIND_IN_SET is an SQL string function that returns the position of a string within a list of strings. The function searches for the first occurrence of a string in a comma-separated values list. The position is based on the number of strings separated by commas before the search term. The function returns the position of the string in the list, not the string itself. If the search term is not found in the list, the function returns 0. It requires two parameters: the string to find and the strings list. Note that FIND_IN_SET is case-sensitive and does not support wildcards or regular expressions.
FIND_IN_SET(str,strlist)
- str: This parameter represents the string to be found. It is the value that will be searched within the set provided in the strlist parameter.
- strlist: This parameter represents the string list within which the search will be performed. It should be a list of substrings separated by commas, wherein the str parameter will be searched.
Example
Output
Explanation
The FIND_IN_SET
function in MySQL is used to search for the position of a string within a list of strings separated by comma. The output ‘2’ denotes that ‘b’ is the second string in the set ‘a,b,c,d’.