The FIND_IN_SET() function returns the position of a string within a comma-separated list of strings. If the string is not found, it returns 0. If either string or string_list is NULL, it returns NULL. If string_list is empty, it returns 0.
MySQL FIND_IN_SET Function Syntax
SQL
x
1
FIND_IN_SET(string, string_list);
MySQL FIND_IN_SET Function Example
This query returns the position of ‘q’ in the string list ‘s,q,l’.
SQL
1
1
SELECT FIND_IN_SET('q', 's,q,l');
Note: The FIND_IN_SET() function is supported in MySQL but not in SQLite. This example does not work in the TechKubo playground.
MySQL FIND_IN_SET Function Parameters
Parameter | Description |
---|---|
string | Required. The string to search for. |
string_list | Required. The list of strings (comma-separated). |
MySQL FIND_IN_SET Function Table Column Example
This query attempts to search for ‘M’ in the list ‘M,F,O’, using the gender column from the Patients table.
SQL
1
1
SELECT FIND_IN_SET('M', gender || ',F,O')
2
FROM Patients;
Note: The FIND_IN_SET() function is supported in MySQL but not in SQLite. This example does not work in the TechKubo playground.
MySQL FIND_IN_SET Function Notes
- Returns
0
if the string is not found.- Returns
NULL
if either string or string_list isNULL
.- Returns
0
if string_list is empty.- Works in MySQL 4.0 and higher.
- Not supported in SQLite. In SQLite, no direct equivalent exists.