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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:58:21+00:00 2026-06-14T16:58:21+00:00

I am using a Linq query to groupBy a column name and return a

  • 0

I am using a Linq query to groupBy a column name and return a list of rows.

var query = from row in ProcessSummaryData.AsEnumerable()
            group row  by new { Key = row .Field<string>("GroupDescription") } into g
            select new 
           { 
             GroupDescription = g.Key, 
             Values = g.ToList(), 

           };

The output of this query is something like this

GroupDescription   Values
1                  12,abc,xyz
                   12,abx,yut
                   13,tye,lki

2                  14,asd,acd

Now the in the above example Values is a DataRow and I have just given an example of values in it.
Now what I want is that for GroupDescription ‘1’ the output only has one row with ’12’ value.
I have tried a few things one of which is to have another Linq query on first list but that’s over complicating things.
How do I use linq to group by first column and then use Distinct on certain column returned list to get only Distinct rows?

  • 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-14T16:58:24+00:00Added an answer on June 14, 2026 at 4:58 pm

    To get the first occurrence of a field’s values you can group by that field and then take the first row of each grouping.

    var query = from row in ProcessSummaryData.AsEnumerable()
                group row  by new { Key = row .Field<string>("GroupDescription") } into g
                select new 
                { 
                    GroupDescription = g.Key, 
                    Values = (from value in g.ToList()
                              group value by value["Id"] into valueGroup
                              select valueGroup.First()).ToList()     
                };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a record that came from the follow linq query: using (var context
I'm using a linq group by query (with two grouping parameters) and would like
How to write the query using linq? SELECT (SELECT SUM([quantity] * [price_usd]) FROM [vi].[dbo].[SALES]
How can I write the following code more elegantly using LINQ query syntax? var
I am using LINQ to EF and have the following LINQ query: var results
How should I structure a Linq query to return a List or Ienumerable of
How would you write this exact same query using the LINQ query syntax? var
Using a linq query, how can i pass parameters into the groupby function? Depend
I'm using a LINQ query on a DataTable where a data field may be
I'm using LINQ to query data. Consider a case where the user only wants

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.