2016-08-23 2 views
-2

에 많은 아무것도 구입하지 않은 고객을 찾기 여기 내 테이블은 다음과 같습니다많은 관계

Customers: 
- CustomerId 
- Name 
- Address 
- ContactNumber 


ProductOrders: 
-PorderKey 
-CustomerId 
-ProductId 


Product: 
-ProductId 
-ProductName 
-ProductDescription 

아직 아무것도 구입하지 않은 고객을 찾을 수 있습니까? 그렇다면 내 쿼리를 어떻게 디자인해야합니까?

+1

지금까지 시도한 것을 공유하십시오. – 1000111

+0

자세한 정보를 추가하겠습니다. –

답변

1

NOT IN 또는 NOT EXISTS 당신이 원하는 것을 : y.some_not_nullable_column이 NULL IS WHERE

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

오오 하시 감사합니다. –

0

는 I, 실제로 y.first_table_id = x.id ON lookup_table Y 가입 first_table X 왼쪽에서 원하는, DISTINCT 열을 선택