Duplicate Output Lines Can I get rid of them? (1 Viewer)

ChampionDuy

Registered User.
Local time
Today, 11:11
Joined
Mar 14, 2002
Messages
94
I have the following SQl statement that returns a number of aspects about a certain record. However each record may have more than one date associated with it that is stored in another table. I receive all teh dates that are associated with it but I also get hundreds of other lines of the same dates just with different combinations of them. How can I get just the dates I want and not all the extras.


PARAMETERS [Enter CCN of case you wish to view] Value, [Enter starting date: (MM/DD/YYYY)] Value, [Enter ending date: (MM/DD/YYYY)] Value;
SELECT DISTINCT [CASEFILE].[TYPE], [CASEFILE].[CRIME], [CASEFILE].[CCN], [CASEFILE].[COMMAND], [CASEFILE].[LOCATE], [CASEFILE].[PERUNIT], [CASEFILE].[APPROVE], [CASEFILE].[AUTH], [RENEW].[RENEW_DATE], [TARDATE].[INT_DATE], [CASEFILE].[EXPDATE], [CASEFILE].[STATUS]
FROM (CASEFILE INNER JOIN RENEW ON [CASEFILE].[CCN]=[RENEW].[CCN]) INNER JOIN TARDATE ON [CASEFILE].[CCN]=[TARDATE].[CCN]
WHERE ([casefile].[auth]>=[Enter starting date: (MM/DD/YYYY)] And [casefile].[auth]<=[Enter ending date: (MM/DD/YYYY)]) Or ([casefile].[expdate]>=[Enter starting date: (MM/DD/YYYY)] And [casefile].[expdate]<=[Enter ending date: (MM/DD/YYYY)]) And [casefile].[ccn]=[Enter CCN of case you wish to view];
 

llkhoutx

Registered User.
Local time
Today, 05:11
Joined
Feb 26, 2001
Messages
4,018
You're not joining your tables correctly.

Use a right or left join to eliminate duplicates.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:11
Joined
Feb 19, 2002
Messages
43,371
The problem is that CaseFile is related to Renew and CaseFile is related to TarDate but Renew and TarDate are not related. So, the record set will be # rows in CaseFile times # rows in Renew times # rows in TarDate.

You can join three tables that are related in a hierarchial manor but you are trying to get data from two separate relationships in the same query and it just cannot be done.

To get an accurate representation of this data, you will need to create a report. The main report will be based on CaseFile, and will contain two subreports. Subreport1 will be based on Renew and Subreport2 will be based on TarDate.
 

ChampionDuy

Registered User.
Local time
Today, 11:11
Joined
Mar 14, 2002
Messages
94
Thanks, I tried the different joins and I got the same result, I am trying the sub reports now. I will let you know how it goes.
 

Users who are viewing this thread

Top Bottom