There are times when we are designing a database, such as:
There is a Type field in the article table, he stores the article type, there are 1 headlines, 2 recommended, 3 hot, 4 graphics ..... 11,12,13, wait.
Now there is an article that he is a headline, hot, or graphic, type in the format of 1,3,4 storage.
So how do we use SQL to find all the 4 texts in the type, and it's time for our find_in_set to come.
First look at the syntax of the Find_in_set function in the MySQL manual:
Find_in_set (Str,strlist)
If the string str is in a string list strlist consisting of N substrings, the return value ranges from 1 to N. A list of strings is a string of self-chains that are separated by ', ' symbols. If the first argument is a constant string and the second is a type set column, the Find_in_set () function is optimized to use bit calculations. If STR is not strlist or strlist is an empty string, the return value is 0. If either parameter is NULL, the return value is null. This function will not work correctly when the first parameter contains a comma (', ').
mysql> SELECT find_in_set (' B ', ' a,b,c,d ');
2
It's easy to use.
Let me give you an example of what I said above:
The following is the referenced content:
SELECT * from article where Find_in_set (' 4 ', type)
How to use the Find_in_set function of MySQL