on 10-18-2008 8:27 AM
Hi,
How do we write query where the same table is repeated more than once since that table has to be join with more than one table .Pls advise.
Rgds,
Rajeev
Rajeev,
When you join the same table more than once use a different Table alais
Example:
[dbo].[ORDR] T0 INNER JOIN ......... [dbo].[ayx]..INNER JOIN [dbo].[ORDR] T2
Using different alias is a way to segregate them
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi sudha,
Pls see the below query :
when I run the below query it returns me all the goods receipt and the corresponding batch details.
SELECT * FROM OIBT T0 RIGHT JOIN PDN1 T9
ON T9.LineNum = T0.BaseLinNum AND T0.BaseNum = T9.DocEntry AND T0.ItemCode = T9.ItemCode
when I run the below query , it gives me duplication .It shows duplicate batch details for goods receipt items.Here in below example the table PDN1 is repeated twice with alias name T1 and T9
SELECT DISTINCT T1.DocEntry"GR No",T1.ItemCode"Part No.", T1.Dscription"Part Description",T0.SuppSerial"DateCode",T0.Quantity"Qty", T2.Custom,T1.Price, T2.Cost FROM PDN1 T1 LEFT JOIN IPF1 T2 ON T2.BaseEntry = T1.DocEntry AND T1.ItemCode = T2.ItemCode AND T2.Origline = T1.LineNum,OIBT T0 RIGHT JOIN PDN1 T9 ON T9.LineNum = T0.BaseLinNum AND T0.BaseNum = T9.DocEntry AND T0.ItemCode = T9.ItemCode
Pls guide me
Rgds,
Rajeev
You can try this rewrite query to see if the results are the same:
SELECT DISTINCT T1.DocEntry 'GR No', T1.ItemCode 'Part No.',
T1.Dscription 'Part Description', T0.SuppSerial 'DateCode',
T0.Quantity 'Qty', T2.Custom,T1.Price, T2.Cost
FROM PDN1 T1
LEFT JOIN IPF1 T2 ON T2.BaseEntry = T1.DocEntry AND
T1.ItemCode = T2.ItemCode AND T2.Origline = T1.LineNum
LEFT JOIN OIBT T0 ON T1.LineNum = T0.BaseLinNum AND
T0.BaseNum = T1.DocEntry AND T0.ItemCode = T1.ItemCode
There are not two alias but one. If you still has duplicate records, it means you have to omit the column with difference data if you can.
Thanks,
Gordon
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.