0

当我有这个时:

SELECT * FROM orders_chosenoptions
RIGHT JOIN orders ON (orders.ID = orders_chosenoptions.order_id)
WHERE orders.deal_id = 982
AND orders.status = 'new'

它给了我 41 行。现在这些行的 orders_chosenoptions.product_id 要么是 110 要么是 111

SELECT * FROM orders_chosenoptions
RIGHT JOIN orders ON (orders.ID = orders_chosenoptions.order_id)
WHERE orders.deal_id = 982
AND orders.status = 'new'
AND (orders_chosenoptions.product_id = 110 OR orders_chosenoptions.product_id = 111)

给我35行?!就像它以某种方式停止了正确的加入?

除了 110 或 110 之外,没有其他行的产品 ID。

4

2 回答 2

0

尝试这个

SELECT * FROM orders_chosenoptions
RIGHT JOIN orders
  ON orders.ID = orders_chosenoptions.order_id
  and orders.deal_id = 982
  AND orders.status = 'new' 
where orders_chosenoptions.product_id = 110
   OR orders_chosenoptions.product_id = 111
于 2012-11-08T12:29:18.113 回答
0

尝试这个::

SELECT * FROM orders_chosenoptions
RIGHT JOIN orders ON (orders.ID = orders_chosenoptions.order_id)
WHERE orders.deal_id = 982
AND orders.status = 'new' AND
orders_chosenoptions.product_id in (110, 111)
于 2012-11-08T12:29:04.263 回答