Many times we have this situation when designing a database. For example:
There is a type field in the article table. It stores the article type. There are 1 headline, 2 recommendation, 3 hot spot, and 4 picture and text. .....11, 12, 13, etc.
Now there is an article that is both a headline, a hot topic, and a picture and text, in the format of 1, 3, 4 in
type Storage.
How do we use sql to find all articles with 4 image and text standards in type?
This is the time for our find_in_set to take action.
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 the string list strlist composed of N sub-chains, the range of the return value Between 1 and N. A string list is a chain of strings separated by ',' characters. If the first argument is a constant string and the second is a column of type SET, the FIND_IN_SET() function is optimized to use bit calculations. If str is not in strlist or strlist is an empty string, the return value is 0. If any parameter is NULL, the return value is NULL. This function will not work properly if the first argument contains a comma (',').