我下面的查詢:如何排除有相同ID的所有行,如果一列不爲空
select oh.id_order,pc.id_product_comment,od.product_id
from `ps_order_history` oh
INNER JOIN `ps_orders` o ON o.id_order = oh.id_order
INNER JOIN `ps_order_detail` od ON od.id_order = oh.id_order
LEFT JOIN `ps_product_comment` pc ON pc.`id_customer` = o.`id_customer` AND pc.`id_product` = od.`product_id`
where oh.`id_order_state` = 2
AND (oh.date_add < pc.date_add OR pc.date_add IS NULL)
返回以下結果:
id_order | id_product_comment | product_id
----------------------------------------------
6 3 6
6 NULL 5
5 NULL 6
5 NULL 5
我想與id_order排除行6,因爲一個行有一個id_product_comment不爲null。 任何想法?
你的意思是你想排除id_order 5,因爲它在id_product_comment中都有NULL值嗎? – Chendur
對不起,我想排除id_order 6,我找到了解決方案 – prestarocket