2016-08-23 25 views
-2

客戶這裏是我的表:發現誰沒有買從許多東西一對多的關係

Customers: 
- CustomerId 
- Name 
- Address 
- ContactNumber 


ProductOrders: 
-PorderKey 
-CustomerId 
-ProductId 


Product: 
-ProductId 
-ProductName 
-ProductDescription 

是否有可能找到誰沒有買任何東西的客戶?如果是的話我應該如何設計我的查詢?

+1

請分享你到目前爲止嘗試過的。 – 1000111

+0

讓我添加更多信息。 –

回答

1

NOT INNOT EXISTS你想要做什麼:

select c.* 
from customers c 
where c.customerid not in (select po.customerid from productorders po); 
+0

Ohhhh好的,謝謝! –

0

SELECT DISTINCT列,我,其實,要從first_table X LEFT JOIN lookup_table是開y.first_table_id = x.id WHERE y.some_not_nullable_column IS NULL