When we search a column in MySQL we use where condition. When we have many records separated by a ‘,’ in a column then searching it becomes bit complex. We can search using like function. It will be clear by taking an example:
Let say we have a record with value – 1,2,3,4,5,6,7,8,9,10,11,12
We want to search say 2. We can search it by using like but when we use it, it will return us this record and other records as well like where values of a column are: 5,10,15,20 or 8,9,10,11,12 i.e. there 2 appearing anywhere in a column. But we wanted results which have columns with 2 as a value not contained in some another number. For this, we can use IN. But when using IN we get results only when 2 (in this case)is the first value. For 1,2,3,4,5,6,7,8,9,10,11,12 as the column value won’t show in results. If it is 2,1,3,4,5,6,7,8,9,10,11,12 then it would show in result. Please look at these two values there is a difference in these two. In first 1 is starting and in second 2 is in starting.
To overcome this, you can use FIND_IN_SET. You can use this by specifying what you want to search and column name. FIND_IN_SET(value, column name). Please note that this value should be one value and you cannot search multiple values. To search multiple values you need to FIND_IN_SET multiple times by using AND or OR.