Difference between IN and FIND_IN_SET in MySQL

Difference between IN and FIND_IN_SET

Most of people thinks IN() and FIND_IN_SET() MySQL functions are identical and do the same job.

But they not. You may be confused with them or don’t know when to use IN() or FIND_IN_SET().There are specific situation for both MySQL functions.

To understand it better assume a table user

Table:user

useridnameagefav_color
1Hitesh Shrimali29Green, Blue
2Jeetendra Sharma 31Blue, Pink
3Ram Singh29Red, Blue
  • IN() mysql Function

This function is used when we want to compare field (which contain single value) with list of values in database.

Result – query will return 2 rows with userid 1 and 2.

  • FIND_IN_SET() mysql function

This function is used when any field holds comma separated values in it and we want to compare it with single value.

Result – query will return 1 row with userid 1.

I hope these will clear your confusion and help you to decide when to use one of them.

Comments