I am trying to update p.product\_status to 0 when two criteria are met.

```
UPDATE product p JOIN product_to_store p2s ON p.product_id = p2s.product_id
SET p.status=0 
WHERE p.quantity=0 AND p2s.store_id=2

```

If the p.product\_id is in p2s and assigned to to p2s.store\_id 2 it should not update p.status to 0.

```
product_id | store_id
         1 |        0
         1 |        2
         2 |        0
         3 |        0
         4 |        2

```

Let's say I have the above data in product\_to\_store.
Product Quantity (p.quantity=0) for all.

**Alt 1.** Product\_id=1 and 4: The SQL should NOT update p.status=0 as product\_id 1 also is assigned to both store\_id 0 and 2.

**Alt 2.** Product\_id=2 and 3: The SQL should update p.status=0 as product\_id 2 is only assigned to store\_id 0 (and not 2).