Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: SQL - Combine multiple records to give 1 record

Re: SQL - Combine multiple records to give 1 record

From: DA Morgan <damorgan_at_psoug.org>
Date: Sat, 27 Aug 2005 17:51:02 -0700
Message-ID: <1125190219.19949@yasure>


ruskie wrote:
> The following query should provide the required output:
>
> select distinct t1.person_id,
> min(t2.start_month) as start_date,
> max(t2.end_month) as end_date
> from temp t1, temp t2
> where t1.start_month <= t2.end_month
> and t2.start_month <= t1.end_month
> group by t1.person_id, t1.start_month, t1.end_month
>
>
> RH

Excuse me but ... SELECT DISTINCT in a GROUP BY?

If a GROUP BY has repeating values they should be dealt with using GROUP_ID() as in the example at www.psoug.org click on Morgan's Library
click on GROUP BY
scroll down to "Group By With Repeating Values"

I suspect you will find it far more efficient.

HTH

-- 
Daniel A. Morgan
http://www.psoug.org
damorgan_at_x.washington.edu
(replace x with u to respond)
Received on Sat Aug 27 2005 - 19:51:02 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US