Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8967501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:15:28+00:00 2026-06-15T17:15:28+00:00

I am new here and I would greatly appreciate some help with a problem

  • 0

I am new here and I would greatly appreciate some help with a problem that I have been struggling with all day.

Consider these 2 tables:

         albums (pkey: id)    years (pkey: album_id, year)

         id   genre_id       album_id  year
         ---  --------       --------  ---- 
         450      1           450      2000
         451      1           450      2001
         452      1           450      2002
         453      2           451      2005
         454      3           451      2012
                              452      1998

It may seem strange, but please assume that a single album can be associated with multiple years.

I want to select all albums in genre 1, sorted by the latest year of each of those albums. (Assume is is possible to sort by year).

So, I want this result:

 id    year
-----  ----
 451   2012
 450   2002
 452   1998

This is where I am at…

Obviously, I need to join the tables before ordering the results:

SELECT      id, year
FROM        albums INNER JOIN years ON albums.id = years.album_id
WHERE       genre_id = 1
ORDER BY    year;

This selects every year record for each album in genre 1, instead of only the latest year record for each album in genre 1.

Somehow, I need to incorporate a sub query, like this, to limit the years joined to the album table, to only the latest year for that album, and then sort again:

SELECT year FROM years WHERE album_id = ??? ORDER BY year DESC LIMIT 1;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:15:29+00:00Added an answer on June 15, 2026 at 5:15 pm
    SELECT   album_id, max(year) latest
    FROM albums INNER JOIN years ON id = album_id
    WHERE genre_id = 1
    GROUP BY album_id
    ORDER BY latest DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am relatively new to db design, so any help here would be appreciated.
That's how I'm new in here on the website so it would be super
am new here. i have a slight problem; PLease look at the following code
I'm new here and have a problem. I am having to pick up C#
I'm new here and I have a problem with the jQuery's function - animate
I'm new here to stackoverflow, so bear with me. I have a book that
I'm new here and I hope anyonte can help me. I have WCF Service
With Netty's new 4.x API, there have been some changes (some big some small).
I am new here. I would like to know how can I display HTML
I am having a problem with seeing subclass attributes in an ArrayList. Here's some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.