SQL operation knowledge for MYSQL SET Fields

Source: Internet
Author: User


Knowledge about SQL operations for MYSQL SET fields [php] <em> 'mark' set ('index', 'best', 'hot ') </em>, there are few people familiar with it. I have been searching for a long time. I finally got a set of knowledge points and looked at the above structure. MYSQL is not stupid. Will it store indexes? No, the number set field is saved using binary numbers to correspond to the values you SET one by one, such as index, which is placed in 0th bits, then the zero side of 2 is equal to 1 www.2cto.com [php] update from table SET mark = 1 [php] 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. The following is the addition of the logo [php] update from table SET mark = mark | 1 | 2 do not ask why I use it | this stuff, the above means to add the index, best two identifiers, if you only add a hot ID, write it as | 4. You can delete the ID [php] update from table SET mark = mark & ~ under www.2cto.com &~ 4 &~ 1. Let me talk about updates. The following describes how to query [php] SELECT * FROM table WHERE FIND_IN_SET ('hot ', mark), which 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: [php] SELECT * FROM table WHERE mark & 1 author longxuu

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.