RE: [PHP-DB] Help with JOIN query
| From: | Gary Wardell | Date: | Thu, 06 Mar 2008 22:35:50 +0000 |
| Subject: | RE: [PHP-DB] Help with JOIN query | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-44709@lists.php.net to get a copy of this message | ||
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@gmail.com]
> Sent: Thu, March 06, 2008 5:17 PM
> To: J. Hill; php-db@lists.php.net
> Subject: Re: [PHP-DB] Help with JOIN query
>
>
> On Thu, Mar 6, 2008 at 9:54 PM, J. Hill <jh@thefirm.biz> 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
>
>