FIND_IN_SET(string,string_set)

Description: If string_set is a string consisting of a set of comma-separated values, function returns a 1 if string matches the first item in the set, 2 for the second, and so on.

Works most efficiently if string_set is a column of type SET because it then uses bit arithmetic. Returns 0 if string is not found in string_set or string_set is the empty string, or NULL if either argument is NULL. Note that string may not contain a comma (,).

Example:

  • FIND_IN_SET('c','a,b,c,d,e') returns 3.

See also: EXPORT_SET(), MAKE_SET()

Get Sams Teach Yourself MySQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.