Re: UNIONS - selecting one record only

From: P. Larsen <plarsen_at_dc.dynares.com>
Date: Mon, 23 Nov 1998 16:36:50 -0500
Message-ID: <73cl9s$7ng8_at_news.uscg.mil>


>The above will return something like:
>00001234 50.00
>00001234 87.00
>
>While if the ID identifiers in both table would have the same name (ex.
>GIFT.ID and MATCHING.ID), the union would return one row only.
This is where you are wrong.
The union has a distinct seletion on all columns - not only the first. A union has no idea what a primary or sort key is. To solve your problem, use the union in a view or in an embedded "view" like:

select col1, sum(col2)
from (select col1, sum(col2) from tab1 group by col1 UNION

         select col1, sum(col2) from tab2 group by col2) group by col1

  • P. Larsen
Received on Mon Nov 23 1998 - 22:36:50 CET

Original text of this message