2017-10-18 2 views
0

나는 세 개의 테이블을 가지고 ...
1) t_quoteMasterSQL에서 중복없이 세 개의 테이블을 조인하는 방법?

quoteId quoteNo quoteDate custName itemName itemQty itemPrice itemToal 
    10  2  17/10/17 cust1  item1  2  100  200 
    11  2  17/10/17 cust1  item2  5  20  100 

2

productId productName productHSN productUnit productPrice 
    15  item1  1111111111  kg   100 
    16  item2  2222222222  gram   20 
    17  item3  3333333333  kg   50 

지금 내가 CUSTNAME에 테이블을 조인 할 t_productMaster) t_custMaster

custId custName custAddress custGSTIN custPhone 
    10  cust1  US  123456789 123456789 
    11  cust2  UK  987654321 987654321 

3) itemName ..
결과는 ..이어야합니다. 각각를 ITEMNAME 10

quoteId quoteNo quoteDate custName itemName itemQty itemPrice itemToal productHSN productUnit custAddress custGSTIN 
    10  2  17/10/17 cust1  item1  2  100  200  1111111111  kg   US  123456789 
    11  2  17/10/17 cust1  item2  5  20  100  2222222222  gram   US  123456789 

CUSTNAME에 기초 에서 에서 t_productMaster을 t_custMaster AND (productHSNproductUnit)을 (custAddresscustGSTIN)을 선택해야 t_quoteMaster에서 t_quoteMaster의 끝에 붙이십시오 ..

,나는 쿼리 아래 시도했지만 많은 기초로 한 공통의 문제입니다 가입 할 때 경우에 ..

SELECT t_quoteMaster.*, 
t_productMaster.productHSN, 
t_productMaster.productUnit, 
t_custMaster.custAddress, 
t_custMaster.custGSTIN 
FROM t_quoteMaster 
INNER JOIN t_productMaster 
ON t_quoteMaster.itemName = t_productMaster.productName 
INNER JOIN t_custMaster 
ON t_quoteMaster.custName = t_custMaster.custName 
where t_quoteMaster.quoteNo = '2' 
+2

중복 결과를 표시 할 수 있습니까? – Harry

+1

이 예제는 중복을주지 않을 것입니다 ... – kbball

+1

그렇기 때문에 OP가 말하고있는 중복 라인을보고 싶습니다. 중복되는 것을 볼 수 없습니다. – Harry

답변

1

복제를 행의 중복을 제공합니다. DISTINCT을 사용하여 중복을 제거 할 수 있습니다.

SELECT DISTINCT t_quoteMaster.*, 
t_productMaster.productHSN, 
t_productMaster.productUnit, 
t_custMaster.custAddress, 
t_custMaster.custGSTIN 
FROM t_quoteMaster 
INNER JOIN t_productMaster 
ON t_quoteMaster.itemName = t_productMaster.productName 
INNER JOIN t_custMaster 
ON t_quoteMaster.customerName = t_custMaster.custName 
where quoteNo = '2' 
+0

DISTINCT를 사용하면 변경되지 않은 문제도 해결되지 않습니다. –

+0

이 답변을 수락하기 때문에이 해결책이기도합니다. –

관련 문제