I have a field of type BIT in my MySQL table. I want to save record statuses using a bit value, for example:
1 = status1 2 = status2 4 = status3 8 = status4
Each record can have several statuses at once. For status1 and status3, the value will be 1 + 4 = 5. I can query the table for all entries with status 3 using:
SELECT * FROM `table` WHERE `statuses` & 4
I have an index on statuses , but EXPLAIN indicates that the index is not used. Is it possible to use the index in such a situation?
PS Using a separate many-to-many link table is a more normal solution, but I would like to have a more βflatβ structure for this.
source share