I have table with the following data in table clients
------------------
|id|client|status|
------------------
|1 |331 | 0 |
|2 |331 | 1 |
|3 |331 | 2 |
|4 |331 | 1 |
|5 |331 | 0 |
|6 |222 | 0 |
------------------
I like to retrieve all the fields from the table clients where client is 331 and having status 0 or 1. That means I will be getting id 1,2,4,5 as the result.
But when i used this sql
$query = mysql_query("select * from clients where client=331 AND status=0 or status=1")
I am getting id 1,2,4,5,6 instead.
Whats the correct way to get the data?
Use
The order of precedence for logical operators is (Not, And, then Or). As
Andhas higher precedence thanOryour query is effectivelyWhich is not the desired semantics. You could also use