MySQL FIND_IN_SET() Function

The FIND_IN_SET() function returns the position of a string within a comma-separated list of strings. If the string is not found, it returns 0. If either string or string_list is NULL, it returns NULL. If string_list is empty, it returns 0.

Tutorials dojo strip

MySQL FIND_IN_SET Function Syntax

SQL

MySQL FIND_IN_SET Function Example

This query returns the position of ‘q’ in the string list ‘s,q,l’.

SQL

Note: The FIND_IN_SET() function is supported in MySQL but not in SQLite. This example does not work in the TechKubo playground.

MySQL FIND_IN_SET Function Parameters

ParameterDescription
stringRequired. The string to search for.
string_listRequired. The list of strings (comma-separated).

MySQL FIND_IN_SET Function Table Column Example

This query attempts to search for ‘M’ in the list ‘M,F,O’, using the gender column from the Patients table.

SQL

Note: The FIND_IN_SET() function is supported in MySQL but not in SQLite. This example does not work in the TechKubo playground.

MySQL FIND_IN_SET Function Notes

  • Returns 0 if the string is not found.
  • Returns NULL if either string or string_list is NULL.
  • Returns 0 if string_list is empty.
  • Works in MySQL 4.0 and higher.
  • Not supported in SQLite. In SQLite, no direct equivalent exists.

Tutorials dojo strip