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: Correlated subquery (?)

Re: Correlated subquery (?)

From: Suresh Easwar <sje_at_sigma-inc.com>
Date: Tue, 14 Apr 1998 23:13:15 -0400
Message-ID: <353425CB.80AFC2E7@sigma-inc.com>


try:

    select D.Time, A.Attrib1, A.Attrib2, A.Attrib3     from Attributes A,

        (select min(Time) Time, Attribute_ID
        from DataPoints
        where Time > Tstart and Time < Tend
        group by Attribute_ID) D

    where A.Attribute_ID = D.Attribute_ID

Suresh

Dick Willis wrote:

> Two tables exist. One has a list of data points and attribute IDs by time.
> The attribute changes slowly, so a separate table exists holding the
> attribute values by attribute ID.
>
> Any attribute will have multiple data points that use the attribute.
>
> I need a query that will return the attribute values for a given range of
> datapoints.
>
> Select D.Time, A.Attrib1, A.Attrib2, A.Attrib3
> from Attributes A, Datapoints D
> where (
> D.Attribute_ID = A.Attribute_ID and
> D.Time > Tstart and
> D.Time < Tend
> )
>
> will not work well enough because it returns lots of D rows; I only need
> the first D row for each unique Attribute record in the range of Datapoints
> from Tstart to Tend.
>
> This seems to be a candidate for correlated subqueries but frankly I am
> having a difficult time
> constructing the appropriate one.
>
> --
> Dick Willis, Senior Engineer
> Synchrony Industrial Controls, Inc.
> rmw_at_synchrony.com
> http://www.synchrony.com
Received on Tue Apr 14 1998 - 22:13:15 CDT

Original text of this message

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