MySQL FIND_IN_SET function is one of the MySQL String Functions, which is useful to find the position of a substring within a string list (N number of string separated by comma) and returns those positions.

Let me show you how to write MySQL String FIND_IN_SET Function query to find and return the position of a string with an example. The basic syntax of FIND_IN_SET of a string in MySQL is as shown below:

FIND_IN_SET(Str, String_List)


The MySQL string Find in Set function finds the position of the first argument inside a second argument, and returns that position as an output. The following query shows multiple ways to use this FIND_IN_SET String Function.

SELECT FIND_IN_SET('c', 'a,b,c,d,e,f');

SELECT FIND_IN_SET('e', 'a,b,c,d,e,f');

SELECT FIND_IN_SET('x', 'a,b,c,d,e,f');
MySQL FIND_IN_SET Function 1

In this MySQL FIND_IN_SET example, we are using the string values and NULL as the first argument.

SELECT FIND_IN_SET('abc', 'an,ball,abc,dog,em,fish');

SELECT FIND_IN_SET('em', 'an,ball,abc,dog,em,fish');

SELECT FIND_IN_SET(NULL, 'an,ball,abc,dog,em,fish');
MySQL FIND_IN_SET Function 2