Getting the "latest" related record from a SQL DB

Jonathan McKeown jonathan at scatterlings.org
Thu Oct 9 18:56:57 BST 2014


On 9 Oct 2014 18:34, "Andrew Beverley" <andy at andybev.com> wrote:
>
> Hi guys,
>
> I'm after some best-practice advice regarding SQL database design.

SWAG (swift wild-arsed guess) rather than best practice....

[snip]
>
> So, if I want to know all of an artist's albums, that's easy.
>
> But what if I want to fetch an artist's details and his latest album? I
> can select the artist from the artists table and then join the albums
> table [snip]

can't you then ORDER BY date DESCENDING FETCH FIRST ROW ONLY? (or LIMIT 1 -
or whichever other syntax your vendor's {per}version of SQL supports)?

jona


More information about the london.pm mailing list