Subject | Re: [firebird-support] Help with DISTINCT predicate |
---|---|
Author | Anderson Farias |
Post date | 2007-11-29T00:37:05Z |
Hi,
From: "sasidhardoc" <madhusasidhar@...>
whetever you prefer:
BEGIN
for
SELECT VisitICD_Description, MIN(VisitICD_ID) FROM CHRT_VisitICD
WHERE Patient_ID = :Patient_ID_IN
AND CHRT_VisitICD.VisitICD_Chronic = 0 AND
CHRT_VisitICD.VisitICD_WasDeleted IS NULL
GROUP BY VisitICD_Description
INTO
:VISITICD_DESCRIPTION,
:VISITICD_ID
do
SUSPEND;
END
HTH,
Regards,
Anderson
I have a stored procedure as follows:
VisitICD_ID is a primary key field that uses a generator. An example
output of the above SP is:
--------
100 Asthma
102 Heart Failure
103 Asthma
104 Lung Cancer
--------
I want to remove the duplicate entry VisitICD_Description = "Asthma"
so that the ouput looks like this:
--------
100 Asthma
102 Heart Failure
104 Lung Cancer
--------
The problem with using DISTINCT is that it makes no difference since
the primary key field is always unique. My application requires both
fields.
From: "sasidhardoc" <madhusasidhar@...>
> Is there an alternate way - perhaps using temporary tables? TIAJust group by VisitICD_Description and get the MIN or MAX VisitICD_ID
whetever you prefer:
BEGIN
for
SELECT VisitICD_Description, MIN(VisitICD_ID) FROM CHRT_VisitICD
WHERE Patient_ID = :Patient_ID_IN
AND CHRT_VisitICD.VisitICD_Chronic = 0 AND
CHRT_VisitICD.VisitICD_WasDeleted IS NULL
GROUP BY VisitICD_Description
INTO
:VISITICD_DESCRIPTION,
:VISITICD_ID
do
SUSPEND;
END
HTH,
Regards,
Anderson
I have a stored procedure as follows:
VisitICD_ID is a primary key field that uses a generator. An example
output of the above SP is:
--------
100 Asthma
102 Heart Failure
103 Asthma
104 Lung Cancer
--------
I want to remove the duplicate entry VisitICD_Description = "Asthma"
so that the ouput looks like this:
--------
100 Asthma
102 Heart Failure
104 Lung Cancer
--------
The problem with using DISTINCT is that it makes no difference since
the primary key field is always unique. My application requires both
fields.