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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:25:10+00:00 2026-06-13T19:25:10+00:00

I am looking for a little help with designing a query using C#/LINQ to

  • 0

I am looking for a little help with designing a query using C#/LINQ to meet the following requirements:

I have a list of companies:-

Id  Name                Email       Address

1   Company A         a@a.com       abc

2   Company B         b@b.com       abc

3   Company C         c@c.com       abc

4   Company D         d@d.com       abc

5   Company A         a@a.com       abc

My goal is to detect duplicate items based on two fields, in this example ‘name’ and ’email’.

Desired output is a list of customers shown below:

  1. Duplicate customers shuold only be shown once
  2. The quantity of similar records should be shown.

Desired duplicate list:-

Id  Qty Name        Email       Address

1   2   Company A       a@a.com     abc (Id/details of first)

2   1   Company B       b@b.com     abc

3   1   Company C       c@c.com     abc

4   1   Company D       d@d.com     abc
  • 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-13T19:25:12+00:00Added an answer on June 13, 2026 at 7:25 pm

    If you explicitly want to use the lowest-ID record in each set of duplicates, you could use

    var duplicates = companies
        .GroupBy(c => new { c.Name, c.Email })
        .Select(g => new { Qty = g.Count(), First = g.OrderBy(c => c.Id).First() } )
        .Select(p => new
            {
                Id = p.First.Id,
                Qty = p.Qty,
                Name = p.First.Name,
                Email = p.First.Email,
                Address = p.First.Address
            });
    

    If you don’t care which record’s values are used, or if your source is already sorted by ID (ascending), you can drop the OrderBy call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a little bit help on this situation. I have a
I am looking for a little bit of help with jqGrid. I have a
I am looking for a little help and I have searched around however found
I'm new to Obj-C and I'm looking for a little help. I have a
I have a rather complex SQL query that I am looking for a little
I'm looking for a little help structuring a web form to include PHP validation
I need a little help with navigating a json file. I'm looking to get
I have heard conflicting stories on this topic and am looking for a little
I have a little / weird behaviour here and Im looking over internet and
I'm looking for a much more idiomatic way to do the following little ruby

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.