Introduction to MYSQL SET type field SQL operation knowledge


<em>`mark` set('index','best','hot')</em> 

With less people, people who understand less, looking for a long time, finally gather together a set of knowledge Look at the structure above, MYSQL is not stupid, would it save index? No, it’s a number The SET field USES the base 2 number 11 to correspond to the value that you set, like index, in the 0th place, so 2 to the zero is equal to 1

update from table SET mark=1 
update from table SET mark='index' 

The above two effects are one. Then the problem comes, just like weaving a dream, if I want to add a popular article, but do not want to delete other logo in the do, or I want to delete a logo, I do not know what logo there was before.

Here is adding the logo

update from table SET mark=mark |1|2

Do not ask me why I use |, the above means to add index, best two signs, if only add hot signs, as |4 is ok

Below is the delete identity

update from table SET mark=mark &~4&~1 

Ok, so I said update first, let’s say query

SELECT * FROM table WHERE FIND_IN_SET('hot',mark) 

This is the simplest query method. You can also use the base 2 number 4 at the location of hot to replace the query. The efficiency is 1 Or you could write it like this:

SELECT * FROM table WHERE mark & 1