![]() |
VOOZH | about |
The FIND_IN_SET() function in MySQL is a powerful tool for searching within comma-separated lists of strings. It allows you to locate the position of a specific string within a list and is commonly used in cases where lists are stored as strings within a database.
In this article, We will learn about FIND_IN_SET() Function in MySQL in detail.
FIND_IN_SET() function in MySQL is used to search for a string within a comma-separated list of strings. Points to be noted:
Syntax:
FIND_IN_SET("string", "string_list")Note: Parameter string is mandatory to search for string_list;
string_list is list of string values.
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 |
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 |
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:
| Query | Result |
|---|---|
FIND_IN_SET("g", "g, e, e, k, s, f, o, r, g, e, e, k, s") | 1 |
The FIND_IN_SET() function is a valuable tool when working with comma-separated values in MySQL. It efficiently identifies the position of a specific string within a list, providing an easy method for searching and indexing.