0

As you can see in the question I need to select all rows that have either of two values given dynamically and where the rows boolean (tinyint) is false

Here is my current query but it is only excluding the rows that have the category_company_id as 0 and category_disabled as 1 and not the ones with category_company_id as 1 and category_disabled as 1

SELECT * FROM `category` 
WHERE `category_company_id` = 1 
OR `category_company_id` = 0 
AND `category_disabled` = 0

What am I doing wrong?

Is there a way of separating the WHERE and OR from the AND?

Thanks in advance

Think_Twice
  • 229
  • 4
  • 18

1 Answers1

1

Your code is equivalent to:

WHERE `category_company_id` = 1 
OR (`category_company_id` = 0 AND `category_disabled` = 0)

because AND has higher priority than OR.
You can use parentheses:

WHERE (`category_company_id` = 1 OR `category_company_id` = 0 )
AND `category_disabled` = 0

or the operator IN:

WHERE `category_company_id` IN (0, 1) AND `category_disabled` = 0
forpas
  • 160,666
  • 10
  • 38
  • 76