On Thu, Mar 6, 2008 at 6:54 PM, Krister Karlström <krister.karlstrom@xxxxxxxxx> wrote: > Hi! > > > Graham Cossey wrote: > > > TableA > > record_id > > product_ref > > > > TableB > > timestamp > > record_id > > action > > > > I want to create a SELECT that joins these 2 tables where the JOIN to > > TableB only returns the most recent entry by timestamp. > > For instance, to select all columns: > > select * from TableA > join TableB on TableA.record_id = TableB.record_id > order by timestamp desc > limit 1 > > So you just join everything, then order by time in descening order and > then just returning the first record = the newest record in the > database. If you don't want all columns, then simply replace the star > with the names of the columns you want. > > I hope that this is what you wanted the query to do.. :) > I was hoping to avoid joining everything as there can be many entries in TableB for each record in TableA. Also wouldn't your query only return one record? I need to return all records from TableA with the latest action from TableB as well. Graham -- Graham -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php