MySQL – Where clause on a comma separated values/String

To perform where clause on comma separated string/values, MySQL has an inbuilt function called FIND_IN_SET which will search for values within a comma separated values. You can also use IN operator to achieve the same but there are some limitations with IN operator which I will show below.

The FIND_IN_SET function takes two arguments and it returns the index position of the first parameter within the second parameter. We use the FIND_IN_SET function when you want to match a value with a comma-separated list of values stored in the database.

Syntax of FIND_IN_SET() function

Parameters or Arguments

search string – The string to find.
string list – The list of string values separated by commas that is to be searched.

Notes

If string is not found in string list, the FIND_IN_SET function will return 0.
If string is NULL, the FIND_IN_SET function will return NULL.
If string list is an empty string, the FIND_IN_SET function will return 0.
If string list is NULL, the FIND_IN_SET function will return NULL.

FIND_IN_SET select examples

MySQL FIND_IN_SET with WHERE CLAUSE example

coming up…

MySQL NOT FIND_IN_SET example

coming up…

MySQL FIND_IN_SET with joins example

coming up…

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun
I am Arjun from Hyderabad (India). I have been working as a PHP Developer from last 6+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.