我的查询select p.idProduct from customer_order c, product p where idProduct not in (select c.product_id from customer_order)
表1产品
1 cooker 500
2 Frying Pane 600
3 Spoon 110
表2 customerOrder
Name product id
Sohaib 1
Sohaib 2
Ammar 2
Max 2
想要获取不在客户订单表中的商品<产品ID
执行上面提到的查询后我得到了
Product id
2
3
1
3
1
3
1
3
答案 0 :(得分:0)
您可以使用not in
或not exists
:
select p.*
from products p
where not exists (select 1
from customerOrder co
where co.productid = p.id
);