FIND_IN_SET Function - How to find position of string in Comma separate values list

FIND_IN_SET Function - How to find position of string in Comma separate values list

FIND_IN_SET function is used to find the position of string in list of comma separated values. FIND_IN_SET can return depending upon the searched value and values present in comma separated list.

Syntax:


FIND_IN_SET( StringtoFind,Comma_Separated_String_List);



  1. Either StringToFind or Comma_Separated_String_List is null, then output is going to be null for find_in_set.
  2. Find_IN_Set will return zero if the StringtoFind is not present in Comma_Separated_String_List.
  3. If StringtoFind is present in Comma_Separated_String_List then positive number will be returned.
Below is example that covers all above scenarios or result set returned by find_in_set.

Select find_in_set('aamir',null),
find_in_set(null,'aamir,shahzad'),
find_in_set('Robert','aamir,shahzad'),
find_in_set('robert','aamir,shahzad,robert,test,test2');


How to use Find_in_set in MySQL to find the position in Comma Delimited value list