Eu tenho três tabelas ...
1) t_quoteMaster
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) t_custMaster
custId custName custAddress custGSTIN custPhone
10 cust1 US 123456789 123456789
11 cust2 UK 987654321 987654321
3) t_productMaster
productId productName productHSN productUnit productPrice
15 item1 1111111111 kg 100
16 item2 2222222222 gram 20
17 item3 3333333333 kg 50
agora eu quero juntar tabelas em custName e itemName ..
o resultado deve ser ..
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
eu preciso selecionar ( custAddress e custGSTIN ) de t_custMaster E ( productHSN e productUnit ) de t_productMaster com base em custName e itemName respectivamente de t_quoteMaster e anexá-lo ao final de t_quoteMaster.
Tentei a consulta abaixo mas se dá duplicação de linhas ..
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'
A duplicação ao ingressar em uma base de um para muitos é um problema comum. Você pode usar DISTINCT
para remover duplicatas.
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'
Este artigo é coletado da Internet.
Se houver alguma infração, entre em [email protected] Delete.
deixe-me dizer algumas palavras