It returns like this because you’re in charge. The OR
cannot be used loosely so it is not natural language text.
SELECT COUNT(id) FROM `system_stats` WHERE `name` = 1 OR 0 AND `us_id` = 0
name = 1
according to you, gives false.
0
gives true, since that is a statement.
us_id = 0
must be giving true
0 AND us_id = 0
gives true. This sub-expression is executed first by the rule of precedence. It is as if it were a multiplication in arithmetic.
False or true, gives true, then returns something you don’t want.
It’s called boolean algebra. If you don’t understand this you won’t be able to program.
Probably what you wanted to do is this:
SELECT COUNT(id) FROM `system_stats` WHERE (`name` = 1 OR `name` = 0) AND `us_id` = 0
I put in the Github for future reference.
Understand the precedence of operators is very important. You have to understand what you do before. Just like knowing that the product takes precedence over the sum, you have to know that the AND
takes precedence over the OR
and if you want to associate the two terms of OR
before taking one of them and associating with the other term of the AND
have to make this explicit in the code through the parentheses.
Other than that, if the problem is another your logic is more confused yet. Your question does not make it very clear what you really want. You need to learn to express yourself well in the program and out of it to achieve the expected results.
name = 1 OR name = 0
– Papa Charlie
Problem persists,
name
is INT with values of 0 or 1 @Papacharlie– Vinícius Lara