Re: Newbie MySQL question: how to retrieve latest entry from a history of entries?

From: davout (davZZZYYYXXXout_at_dial.pipex.com)
Date: 08/26/04


Date: Thu, 26 Aug 2004 07:53:44 +0100

Your query isn't accepted by MySQL R4.x

"Frank Bates" <fbates@sbcglobal.net> wrote in message
news:hWcXc.3286$8G2.39@newssvr31.news.prodigy.com...
> Consider:
> select s.*, ss.*
> from station s
> , stationstatus ss
> , (select StationID, max(StatusDate)
> from stationstatus
> group by StationID) m
> where ss.StationId=s.StationID
> and ss.StationId=m.StationID
> and ss.StatusDate=m.StatusDate
> order by ...
>
> davout wrote:
> > I'm using MySQL 4.0.16
> >
> > How do I join two tables - one a master table, the second a detail table
> > holding multiple status entries for each master table entry - so that a
> > query can return the master table fields plus the latest status fields
(the
> > status entry with the most recent date)?
> >
> > table : station
> > Fields: StationID INTEGER, StationName VARCHAR
> >
> > e.g.
> > 1, London
> > 2 ,Brighton
> >
> > table: stationstatus
> > Fields: StationID, StatusDate, Metric1,Metric2,Metric3
> >
> > e.g.
> >
> > 1, 23/8/04, 1, 1, 1
> > 1, 24/8/04, 2, 2, 2
> > 1, 25/8/04, 3, 3, 3
> > 2, 23/8/04, 4, 4, 4
> > 2, 24/8/04, 5, 5, 5
> > 2, 25/8/04, 6, 6, 6
> >
> > What I'm looking for is a query that returns
> >
> > StationID,StationName,StatusDate,Metric1,Metric2,Metric3
> >
> > e.g.
> >
> > 1, London, 3, 3, 3,
> > 2, Brighton, 6, 6, 6
> >
> > Any ideas?
> >
> >
>



Relevant Pages

  • Re: use a result as a FIELD in the design grid
    ... I have a key TableA that maps each station's flow (and ... Station: FlowField: TankLevel: PumpRun: ... OK, now from the previous query, I know that the FlowField ... So in a new query grid where TableA is linked to TableB ...
    (microsoft.public.access.queries)
  • Re: Creating an autonumber ID field in a make table query?
    ... It worked but the autonumber ID field doesn't reset to 1. ... "Jeff Boyce" wrote in message ... I link access to our oracle database through ODBC and download the data for a particular station and then crunch the data. ... I use a pass through query as a front end to a "make table query". ...
    (microsoft.public.access.queries)
  • Re: Creating an autonumber ID field in a make table query?
    ... are you trying to use Autonumber values as "meaningful"? ... database through ODBC and download the data for a particular station ... I use a pass through query as a front ... If I could in a macro, delete all records, run an "append" query instead ...
    (microsoft.public.access.queries)
  • Re: Creating an autonumber ID field in a make table query?
    ... hold intermediate work products, then delete all the rows before re-use. ... stations have a station number) and then crunch the data. ... "make table query". ... If I could in a macro, delete all records, run an "append" query instead ...
    (microsoft.public.access.queries)
  • Re: Creating an autonumber ID field in a make table query?
    ... I'm using access as an analysis tool. ... I link access to our oracle database through ODBC and download the data for a particular station and then crunch the data. ... I use a pass through query as a front end to a "make table query". ... If I could in a macro, delete all records, run an "append" query instead with the make table as a front end that would do the trick. ...
    (microsoft.public.access.queries)