In MySQL, sometimes when we are doing database queries, we need to get a record of a certain value in a field, but it is not solved with like, we can find the record that we do not want, and it is more accurate than the find_in_. The set function comes in handy, and here's a concrete look.
Find_in_set (str,strlist) function
STR string to query for
Strlist field name parameters are separated by "," as (1,2,6,8)
Query field (strlist) contains the result of (str), the result is null or the record
The following examples illustrate
The test table has the following fields and values
Below I want to query the area contains "1″ This parameter record
SELECT * FROM Test where find_in_set (' 1 ', area)
return value
The following query btype field contains "15″ the value of this parameter
SELECT * FROM Test where find_in_set (' btype ')
return value
The following query btype field contains "5″ the value of this parameter
SELECT * FROM Test where Find_in_set (' 5 ', btype)
The return value is NULL because there is no value of "5" in Btype, which is different from a like fuzzy query, which separates values with ","
Next Query the Btype field contains the value of the 20″ parameter
SELECT * FROM Test where find_in_set (' a ', btype)
Of course, its return value is NULL, because there is no value in the field
The difference between find_in_set and like
Like is a broad fuzzy match, there is no delimiter in the string, Find_in_set is exact match, the field value is delimited in English "," and the result of the Find_in_set query is less than the result of the as query.
Reference URL: http://www.cnblogs.com/manongxiaobing/p/4682698.html
How to use Find_in_set in MySQL