Re: Help with JOIN query
| From: | Krister Karlström | Date: | Thu, 06 Mar 2008 18:54:46 +0000 |
| Subject: | Re: Help with JOIN query | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-44701@lists.php.net to get a copy of this message | ||
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.. :) Cheers, Krister Karlström, Helsinki, Finland