Introduction to SQL Operations knowledge for MYSQL set type fields _mysql

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.