View Full Version : Duplicate Output Lines Can I get rid of them?


ChampionDuy
05-07-2002, 04:34 AM
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
05-07-2002, 08:44 PM
You're not joining your tables correctly.

Use a right or left join to eliminate duplicates.

Pat Hartman
05-07-2002, 08:44 PM
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
05-08-2002, 06:43 AM
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.

ChampionDuy
05-14-2002, 11:50 AM
finally figured it out, thanks for all your help