Many times we have this in the design of a database, such as:
There is a Type field in the article table, he stores the article type, has 1 headlines, 2 recommendations, 3 hotspots, 4 text ... 11,12,13, wait.
Now there is an article he is a headline, hot, or graphic,
Type is stored in a 1,3,4 format.
So how do we use SQL to find Articles with 4 text standards in all of the type?
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 string str is in the strlist of a string list of n chains, the return value ranges from 1 to N. A list of strings is a string of strings that are separated by a number of ', ' symbols. If the first argument is a constant string, and the second is the Type SET column, the Find_in_set () function is optimized, using bit computations. If STR is not strlist or strlist is an empty string, the return value is 0. If any of the arguments are null, the return value is null. This function will not work correctly when the first argument contains a comma (', ').
Copy Code code as follows:
mysql> SELECT find_in_set (' B ', ' a,b,c,d ');
-> 2
It's easy to use.
As I said above, for example:
The following are the referenced contents:
Copy Code code as follows:
SELECT * from article where Find_in_set (' 4 ', type)