FIND_IN_SET() Function in MySQL

FIND_IN_SET() function used to find the position of a string within a list of strings. If the string is repeated multiple time, the output will be the first position of that string.

Point to be noted :

  • If string is not found in string_list, the result is 0
  • If string or string_list is NULL, the result is NULL
  • If string_list is an empty string (“”), the result is 0

Syntax :

FIND_IN_SET("string", "string_list")

Note : Parameter string is mandatory to search for string_list; string_list is list of string values.

Example-1:
Search for “a” within the list of strings :



SELECT FIND_IN_SET("a", "g, e, e, k, s, f, o, r, g, e, e, k, s"); 

Result –

FIND_IN_SET(“a”, “geeksforgeeks”)
0

Example-2:
Search for “q” within the list of strings (string list is NULL) :

SELECT FIND_IN_SET("a", null); 

Result –

FIND_IN_SET(“a”, null)
null

Example-3:
Search for “q” within the list of strings :

SELECT FIND_IN_SET("g", "g, e, e, k, s, f, o, r, g, e, e, k, s"); 

Result –

FIND_IN_SET(“g”, “g, e, e, k, s, f, o, r, g, e, e, k, s”)
1
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.