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 989723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:50:16+00:00 2026-05-16T05:50:16+00:00

I have a table in my database representing releases of software; the relevant columns

  • 0

I have a table in my database representing releases of software; the relevant columns of the schema being as follows:

ProductID   int
PlatformID  tinyint
Date        datetime

All are not null, and there is also a unique key assigned to the first two columns.

I would like to build a query (using LINQ) which returns the latest release (e.g. Date) for each platform (PlatformID), but no more than one record per platform (PlatformID), and is sorted by Date descending.

How can I do this?


EDIT: Here is the solution I used:

var product = ...;

var latestReleases = product.Releases
    .GroupBy(p => p.PlatformID)
    .Select(group => group.OrderByDescending(p => p.Date).FirstOrDefault())
    .OrderByDescending(release => release.Date)

for clarity…

foreach (var release in latestReleases)
{
    Console.WriteLine("The latest release of MyProduct for {0} is {1}.",
        release.PlatformID, // of course this would be a string in real code ;)
        release.Version);
}
  • 1 1 Answer
  • 1 View
  • 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-05-16T05:50:17+00:00Added an answer on May 16, 2026 at 5:50 am

    I think the following code does what you’re asking for:

    var latestProducts = db.Releases
        .GroupBy(p => p.PlatformID)
        .Select(grp => new {
            Platform = grp.Key,
            Latest = grp.OrderByDescending(p => p.Date).FirstOrDefault()
        })
        .OrderByDescending(entry => entry.Latest.Date);
    
    foreach (var entry in latestProducts)
    {
        Console.WriteLine("The latest product for platform {0} is {1}.",
            entry.Platform,
            entry.Latest.ProductID);
    }
    

    Here’s how it works:

    • First, take all the products
    • Group them into groups by common PlatformID
    • Within each group, sort the products in that group by date descending and pick the first (that’ll be the one with the latest date)
    • For each group, create an object containing the PlatformID and the platform’s latest Product
    • Sort this list of objects by date descending.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a class representing access to one table in my database in
I have a database table named call with columns call_time, location, emergency_type and there
i have database table like this +-------+--------------+----------+ | id | ip | date |
i have a database table of website links. i have another table of tags,
I have a table in database that is having some fields one of which
that my problem: I have database table like that: id (AI) market_id 1 6
I have a database table and one of the fields (not the primary key)
I have a database table that i want to allow my friends to update.
I have a database table on a development server that is now fully populated
I have a database table (named Topics) which includes these fields : topicId name

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.