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

  • Home
  • SEARCH
  • 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 8149425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:50:56+00:00 2026-06-06T14:50:56+00:00

Below I have table – Company id name value year 1 IBM 10 2011

  • 0

Below I have table – Company

  id name value year
    1  IBM   10   2011
    2  IBM   30   2012
    3  IBM   10   2012
    4  C     10   2010

I want to group records by name and from each group return only one record with maximum id. All results combine into the list of companies using linq where year is greater 2011. For my example output should be – “3 IBM 10 2012”

I did write something but does not working.

var a = from x in companies where x.year > 2011
                  group x by new {x.name, x.value, x.ID, x.year } into g
                  select new {
                                  g.Key.name,
                                  g.Key.value,
                                  g.Max(a=>a.ID),
                                  g.Key.value
                              };
 return a.ToList();
  • 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-06T14:50:57+00:00Added an answer on June 6, 2026 at 2:50 pm

    Try this:

      var a = from x in companies
                    where x.Year > 2011
                    group x by new { x.Name } into g
                    from x1 in companies
                    where x1.ID == (from x2 in g select x2.ID).Max()
                    select x1;   
    

    Or something more efficient:

    var a = from x in companies
                        where x.Year > 2011
                        group x by new { x.Name } into g
                        join x2 in companies on (from x3 in g select x3.ID).Max() equals x2.ID
                        select x2;  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have table name FriendsData that contains duplicate records as shown below fID
I have table with below fields, table Shows, Id Name Time 1 A 7/28/2010
I have a table as below Name Priority Date ------------------------- A 2 d1 B
I have a table as below dbo.UserLogs ------------------------------------- Id | UserId |Date | Name|
I have table like below id, employee_no, survey_no, name 1 test 1 test_name 2
I have Table MultiCol as below Name LibraryID RegisterID EngineerID Rahul 1002 4521 4854
I have below table structure in MS SQL AirQuoteID Name SalesValue 7 M 49.50
I have a table in MSSQL as below : I want to create a
I have table like below ID User Date Location 1 Tom 6-Mar-2012 US 2
I have table tblTask with data like below. TID StartTime Uid WId 1 2011-06-06

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.