2016-08-23 6 views
-2

に多くのものを買っていない顧客を見つけるここに私のテーブルは以下のとおりです。多くの関係

Customers: 
- CustomerId 
- Name 
- Address 
- ContactNumber 


ProductOrders: 
-PorderKey 
-CustomerId 
-ProductId 


Product: 
-ProductId 
-ProductName 
-ProductDescription 

それはまだ何も買っていない顧客を見つけることは可能ですか?もしそうなら、どのように私の質問をデザインするのですか?

+1

これまでに試したことを教えてください。 – 1000111

+0

詳細を追加します。 –

答えて

1

NOT INまたはNOT EXISTSあなたが欲しいものを行います。

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

オハイオ州いいよ、ありがとう! –

0

DISTINCT列を選択し、私は、実際には、first_table X左からたくはy.first_table_id = x.id y.some_not_nullable_columnが

NULLされている場所にlookup_table Yを登録しよう