Copy codeThe Code is as follows:
<Em> 'mark' set ('index', 'best', 'hot ') </em>
There were few users and few people who knew about it. After a long time, I finally got a set of knowledge points.
Looking at the above structure, MYSQL is not stupid. Will it store indexes? No, it stores numbers.
The SET field uses binary numbers to correspond to the values you SET one by one. For example, if the index is in The 0th bits, then the zero side of 2 is equal to 1.
Copy codeThe Code is as follows:
Update from table SET mark = 1
Copy codeThe Code is as follows:
Update from table SET mark = 'index'
The above two results are the same.
Then the problem arises, just like zhimeng. If I want to add a popular article, but do not want to delete other identifiers, do it? Or I want to delete an identifier, I don't know what logo I used to have.
Add an ID
Copy codeThe Code is as follows:
Update from table SET mark = mark | 1 | 2
Don't ask why I use it | this stuff, which means adding the index and best identifiers. If you only add the hot identifiers, write them as | 4.
Below is the deletion identifier
Copy codeThe Code is as follows:
Update from table SET mark = mark &~ 4 &~ 1
Okay, I will talk about updates first, and I will talk about queries below.
Copy codeThe Code is as follows:
SELECT * FROM table WHERE FIND_IN_SET ('hot ', mark)
This is the simplest query method. You can also use the binary number 4 in the hot location to replace the query. The efficiency is the same.
You can also write this statement:
Copy codeThe Code is as follows:
SELECT * FROM table WHERE mark & 1