Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

FIND_IN_SET

Example

Look for the occurrence of “q” within the list of strings.

SELECT FIND_IN_SET(“q”, “s,q,l”); 

Definition and Usage

The FIND_IN_SET() function retrieves the position of a string within a comma-separated list of strings.

Syntax

FIND_IN_SET(string, string_list)

Parameter Values

Parameter

Description

string

Necessary: The string to be searched.

string_list

Necessary: The list of string values to search within, separated by commas.

Return Values

  • If the specified string is not found within the list of strings, the function returns 0.
  • If either the string or the list of strings is NULL, the function returns NULL.
  • If the list of strings is an empty string (“”), the function returns 0.

Technical Details

Works in: From MySQL 4.0

More Examples

Example

Find the occurrence of “a” within the provided list of strings.

SELECT FIND_IN_SET(“a”, “s,q,l”); 

Example

Look for “q” within the list of strings (if the string list is NULL).

SELECT FIND_IN_SET(“q”, null);