Berstos
Berstos

Reputation: 179

Check if flags are set and not set in MySQL query

I have two flags (64 and 32) and I need to check if "64" is set and "32" is NOT set inside a "MySQL column value" (quest_template.Flag).

The value of the column quest_template.Flag is: "824183885".

Therefore I use the following query:

SELECT * FROM quest_template
WHERE quest_template.ID > 0
AND 64 & quest_template.Flag AND 32 != quest_template.Flag 

At the moment I have the problem that the query just checks if the "64" is set but not if the "32" is NOT set.

Where is the mistake in the query?

Upvotes: 1

Views: 946

Answers (1)

Barmar
Barmar

Reputation: 781120

You need to use & to mask with a bit flag. Then just check if it's 0 or 1.

SELECT * FROM quest_template
WHERE quest_template.ID > 0
AND 64 & quest_template.Flag = 1
AND 32 & quest_template.Flag = 0

Upvotes: 2

Related Questions