mysql query - exclude an entry
I have 2 tables, 1 table is order and another table is order_items. Order_items contains many records for a order_id from order. I would like to query table order so that, if the orders contain certain order_items (such as product_item = 'nameProduct'
). it would exclude these orders out of the result. how should I do it?
My current queries are:
select * orders where order_id in (select order_id from order_items where product_item !='nameProduct');
this query not really working b开发者_运维知识库ecause the select order_id from order_items where product_item !='nameProduct'
can still select entry that has same order_id
but just has a different product_item
thanks in advance!
SELECT *
FROM orders o
WHERE NOT EXISTS ( SELECT *
FROM order_items oi
WHERE product_item = 'nameProduct'
AND oi.order_id = o.order_id )
精彩评论