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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:22:52+00:00 2026-05-21T10:22:52+00:00

I have a list that looks something like this: catId itemId value 1 5

  • 0

I have a list that looks something like this:

catId    itemId    value
  1        5         "some text"
  1        19        "some text"
  1        21        "some text"
  2        6         "some text"
  2        8         "some text"
  3        9         "some text"
  3        82        "some text"

Notice the catId column. How would I take 2 rows(or remove extra rows) for each unique value in the first colum. Only 2 rows for catId=1 2 rows for catId=2 and so on?

My list is called distinctXSelling and I’m using it like this currently:

            foreach (var item in distinctXSelling)
            {
                xSelling.InnerHtml += item.value;
            }
  • 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-05-21T10:22:52+00:00Added an answer on May 21, 2026 at 10:22 am

    You can group items by their category-id and then pick the first two items from each group, before flattening the sequence of groups into a sequence of source-items. This would look like:

    var query = source.GroupBy(item => item.catId)
                      .SelectMany(catGroup => catGroup.Take(2));
    

    Note that the Take method takes upto a certain number of items, so this won’t throw if a category has only a single item.

    As BrokenGlass points out, you might need a .OrderBy (and possibly a .ThenBy) if you want the filtered items out in a specific order.

    You might also want to consider replacing the loop with:

    xSelling.InnerHtml = string.Concat(query.Select(item => item.value));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that looks something like this where the first column
Some existing web services I consume have methods that look something like this: List<Employee>
I have a list of dictionaries that looks something like this: toCSV = [{'name':'bob','age':25,'weight':200},{'name':'jim','age':31,'weight':180}]
I have a list of topic categories that looks something like this mockup: http://www.problemio.com/problems/categories.php
I have a class, and list of instances, that looks something like this (field
I have a huge mess of a nested list that looks something like this,
I have an xml file that looks something like this <questions> <question> <text>What color
I have a long list that of which a snippet looks something like this:
Alright I have an xml document that looks something like this: <xml> <list> <partner>
I have a list of lists that looks something like this: data = [['seq1',

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.