FIND_IN_SET function in MySQL

If a string is found in a string list with N substrings, the “Find in set” function returns a value in the “1 to N” range. Using commas to separate each substring makes a string list (,). The FIND IN SET() function is streamlined to use bit arithmetic if the first parameter is a constant string and the second argument is a column of type SET. If the string isn’t found in the string list, returns 0. If either parameter is NULL, NULL is returned. If there is a comma (,) in the first argument, this function will not function correctly.

In short, the FIND_IN_SET() function returns the position of a string within a list of strings.

SELECT FIND_IN_SET(‘Sports’,’Sports,Games,Arts,Crafts’);

This function can be used in WHERE clause too.

SELECT * FROM Emp WHERE find_in_set(‘MANAGER’,Job) <> 0;

Hope you find this article helpful.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s