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

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

FIND_IN_SET(Str, String_List)

MySQL FIND_IN_SET Function Example

The Find in Set method 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 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 Example 1

In this MySQL 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');
FIND_IN_SET Function 2