# SQL: most recent using multiple tables

**URL:** <https://forum.kirupa.com/t/sql-most-recent-using-multiple-tables/236062>\
**Category:** programming\
**Created:** [August 16, 2007, 8:40pm UTC](https://forum.kirupa.com/t/sql-most-recent-using-multiple-tables/236062 "2007-08-16T20:40:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![boondocksaint2k](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/boondocksaint2k/32/3453_2.png) [@boondocksaint2k](https://forum.kirupa.com/u/boondocksaint2k)\
**Post date:** [August 16, 2007, 8:40pm UTC](https://forum.kirupa.com/t/sql-most-recent-using-multiple-tables/236062/1 "2007-08-16T20:40:51Z")

</div>

Hi, I have three tables:  
\*\*work \*\*- contains details on each artwork; _id, date, title, description, type_  
\*\*albums \*\*- contains album names; _id, album_  
\*\*wa \*\*- the relationship table; _work\_id, album\_id_

For a page in my gallery, I need to display a list of albums with thumbnail image of the most recent work in each album as the album’s cover art.

This is the query I’m using:  
SELECT a.id AS album\_id, a.album AS album\_name, w.id AS work\_id  
FROM albums AS a, work AS w, wa AS r  
WHERE r.album\_id = a.id AND r.work\_id = w.id GROUP BY a.id

However, it does not return the most recent records (which is right, because I haven’t told it anything about dates), and what I don’t know is what I should write and where it should be.

It returns:  
“album\_id”,“album\_name”,“work\_id”  
1,“sketches”,1  
2,“paintings”,2  
3,“collaborations”,3  
5,“temp”,5

But in the temp album, there’s a more recent artwork with an id of 6.

Please help me, I tried looking in other places but none of the examples I found matched my situation and I just can’t figure it out.

Thank you for your time,  
Michael Popov
