Re: Help with JOIN query

From: Date: Thu, 06 Mar 2008 22:17:08 +0000
Subject: Re: Help with JOIN query
References: 1 2 3 4  Groups: php.db 
Request: Send a blank email to php-db+get-44708@lists.php.net to get a copy of this message
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

« previous php.db (#44708) next »