Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Duplicate data results

Author  Topic 

ukkz001
Starting Member

15 Posts

Posted - 2007-07-16 : 12:51:13
I have a query joining two tables but is returning duplicate data even though I am grouping?
Example:
Select L.Client, L.FltNbr, L.LegNbr, G.Acct as MEALS, G.DRAmt, G.PerPost
From xLegHdr L
Inner Join
(Select ProjectID,Acct,DrAmt,PerPost
From GLTran
Group By ProjectID,Acct,DrAmt,PerPost) G
ON L.FltNbr = G.ProjectID
Where G.Acct = '530002'
AND G.PerPost Between '200601' AND '200612'

Any Suggestions on how to better group the data so there are not duplicates?

Thanks,

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-07-16 : 13:00:08
Which query is returning duplicates? The inner one or the outer one?
Use a GROUP BY on the outer select and see if it makes any difference.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

ukkz001
Starting Member

15 Posts

Posted - 2007-07-16 : 13:17:34
It did not make a difference. Both queries return duplicates and using the Group By on the outer Select
did not work.
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-07-16 : 13:22:49
Can you post some sample data from each table and expected output?

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

mattyblah
Starting Member

49 Posts

Posted - 2007-07-16 : 13:26:07
can you not use distinct?


Select distinct L.Client, L.FltNbr, L.LegNbr, G.Acct as MEALS, G.DRAmt, G.PerPost...
Go to Top of Page

ukkz001
Starting Member

15 Posts

Posted - 2007-07-16 : 14:22:16
I will try Distinct.
Go to Top of Page

ukkz001
Starting Member

15 Posts

Posted - 2007-07-16 : 14:31:29
I tried the following query and I'm still getting duplicates.
Select Distinct L.Client, L.FltNbr, L.LegNbr, G.Acct as MEALS, G.DRAmt, G.PerPost
From xLegHdr L
INNER JOIN GlTran G ON G.ProjectID = L.FltNbr
Where G.Acct = '530002'
AND G.PerPost Between '200601' AND '200612'
Group by L.Client, L.FltNbr, L.LegNbr, G.Acct, G.DrAmt, G.PerPost
Go to Top of Page

mattyblah
Starting Member

49 Posts

Posted - 2007-07-16 : 22:56:35
if any of the fields are datetime then you will probably have a problem. datetime tracks to the 1/3 of a second, iirc.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-16 : 22:59:23
quote:
Originally posted by dinakar

Can you post some sample data from each table and expected output?

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/




KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -