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_list includes string, the function will return the corresponding position number.
  • If string_list does not include string, the function will return 0.
  • If string is NULL, the function will return NULL.
  • If string_list is an empty string, the function will return 0.
  • If string_list is NULL, the function will return NULL.

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)