I have 2 tables `books` and `books_details`. I want to look up results from the `books` table and only get the correlating `books_details` result that has the highest date. I can't work out the MySQL query. Any help would be great. Thanks!
{table `books`}
[id] [book_title]
01 Little Red Riding Hood
02 Tom's Adventure
03 Baby Boo
{table `books_details`}
[id] [content_id] [content] [date]
01 01 1st version 20-01-2009
02 01 2nd version 22-01-2009
03 01 3rd version 25-01-2009
04 02 1st version 22-01-2009
05 02 2nd version 24-01-2009
06 02 3rd version 25-01-2009
07 02 4th version 27-01-2009
08 02 5th version 28-01-2009
09 03 1st version 22-01-2009
10 03 2nd version 27-01-2009
{** Non working MySQL }
SELECT `book_details`.`id`, `books_details`.`content_id`, `books`.`book_title`, `book_details`.`content`, MAX(`books_details`.`date`)
FROM `books`, `books_details`
WHERE `books`.`id` = `books_details`.`id`
GROUP BY `books_details`.`content_id`
{** Current Results}
01 01 Little Red Riding Hood 1st version 25-01-2009
04 02 Tom's Adventure 1st version 28-01-2009
09 03 Baby Boo 1st version 27-01-2009
At the moment it just groups the records and only gets the max date and not the row associated with the max date.
{** Wanted Results }
03 01 Little Red Riding Hood 3rd version 25-01-2009
08 02 Tom's Adventure 5th version 28-01-2009
10 03 Baby Boo 2nd version 27-01-2009
{table `books`}
[id] [book_title]
01 Little Red Riding Hood
02 Tom's Adventure
03 Baby Boo
{table `books_details`}
[id] [content_id] [content] [date]
01 01 1st version 20-01-2009
02 01 2nd version 22-01-2009
03 01 3rd version 25-01-2009
04 02 1st version 22-01-2009
05 02 2nd version 24-01-2009
06 02 3rd version 25-01-2009
07 02 4th version 27-01-2009
08 02 5th version 28-01-2009
09 03 1st version 22-01-2009
10 03 2nd version 27-01-2009
{** Non working MySQL }
SELECT `book_details`.`id`, `books_details`.`content_id`, `books`.`book_title`, `book_details`.`content`, MAX(`books_details`.`date`)
FROM `books`, `books_details`
WHERE `books`.`id` = `books_details`.`id`
GROUP BY `books_details`.`content_id`
{** Current Results}
01 01 Little Red Riding Hood 1st version 25-01-2009
04 02 Tom's Adventure 1st version 28-01-2009
09 03 Baby Boo 1st version 27-01-2009
At the moment it just groups the records and only gets the max date and not the row associated with the max date.
{** Wanted Results }
03 01 Little Red Riding Hood 3rd version 25-01-2009
08 02 Tom's Adventure 5th version 28-01-2009
10 03 Baby Boo 2nd version 27-01-2009