Open In App

FIND_IN_SET() Function in MySQL

Improve
Improve
Like Article
Like
Save
Share
Report

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

Last Updated : 02 Sep, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads