RE: Help with JOIN query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

The way I think I'd approach it is to use an outer join where table a is joined to a subquery where the subquery returns only the
max timestamp from table b.

Gary

> -----Original Message-----
> From: Graham Cossey [mailto:graham.cossey@xxxxxxxxx]
> Sent: Thu, March 06, 2008 5:17 PM
> To: J. Hill; php-db@xxxxxxxxxxxxx
> Subject: Re:  Help with JOIN query
>
>
> On Thu, Mar 6, 2008 at 9:54 PM, J. Hill <jh@xxxxxxxxxxx> wrote:
> > I may be a little confused: the desire is to return all the
> rows from
> >  TableA that match the record_id of a row in TableB that has the MAX
> >  timestamp?
> >
> >  If so, why not something like:
> >
> >  SELECT * FROM TableA a, TableB b WHERE a.record_id=b.record_id &&
> >  timestamp=(SELECT MAX(timestamp) FROM TableB) ORDER BY action;
> >
> >  I'm guessing I'm confused, that it's something more
> complicated you're
> >  looking for.
> >
>
> Thanks Krister and all for your help thus far.
>
> Jeff, I'm after all rows from TableA then the latest action from
> TableB for each selected record in TableA.
>
> I'm starting to think maybe I should build an array of results using 2
> queries then sort the array using PHP functionality, but I'd rather do
> it in MySQL if it's possible.
>
> Graham
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux