This article is a MySQL in the Set Type field of SQL Operation knowledge for a detailed analysis of the introduction, the need for friends under the reference
copy code code as follows:
<em> ' Mark ' Set (' Index ', ' best ', ' hot ') </em>
The use of fewer people, understand less people, looking for a long time, finally gathered a set of knowledge points
Look at the structure above, MySQL is not stupid, will deposit index, will not, the number is stored
Set field is to use binary digits to one by one corresponding to the value you set, such as index, ranked No. 0, then 2 of 0 times equals 1
Copy Code code as follows:
Update from table SET mark=1
Copy Code code as follows:
Update from table SET mark= ' index '
the above two effects are the same.
then came the question, like weaving a dream, if I wanted to add a hot article, but I didn't want to delete the other logo, or I wanted to delete an identity, and I didn't know what it was before.
here's how to add an identity
Copy Code code as follows:
Update from table SET Mark=mark |1|2
Don't ask me why I use | This dongdong, the above meaning is to add index, best two logo, if only add Hot logo, written |4 can be
The following is the deletion of identities
Copy Code code as follows:
Update from table SET Mark=mark &~4&~1
OK, I said the update first, the following query
Copy Code code as follows:
SELECT * FROM table WHERE find_in_set (' hot ', Mark)
This is the simplest query method, you can also use the location of hot binary number 4来 alternative query, efficiency is the same
You can also write this:
Copy Code code as follows:
SELECT * FROM table WHERE Mark & 1