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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:54:39+00:00 2026-06-18T04:54:39+00:00

Ive been struggling to find an answer to this task problem I am solving,

  • 0

Ive been struggling to find an answer to this task problem I am solving, despite spending the morning no here searching.
I have looked into the MIN/MAX clauses but cannot seem to fit it in my scenario properly.

I am performing this simple LINQ query where i search all rows where the column matches

using (DataClasses2DataContext db = new DataClasses2DataContext())
        {
            var routes = (

                          from txcalllines in db.TxcAllLines
                          where
                              txcalllines.LineName == searchString
                          select txcalllines);

            return routes.ToList();
        }

And this returns these results:

FILE                           LINE   START               FINISH
output_txc_45486m.xml           486   North Station       Friswell Place
SVRAYAO486-20121008-22264.xml   486   Dunoon              Inveraray
SVRAYAO486-20121008-22265.xml   486   Dunoon              Inveraray
SVRAYAO486-20121008-22266.xml   486   Dunoon              Inveraray
SVRGMB04860-20120103-5774.xml   486   BURY                RADCLIFFE
SVRGMB04860-20120103-5775.xml   486   BURY                RADCLIFFE
SVRYNAO486-20120217-44588.xml   486   Selby Bus Stn       Pollington Circular

The problem is, running this query returns several rows of the same route (you can see LINE, START, and FINISH are the same), where I only want to return the first matching row of each route.

So the desired result would be:

FILE                           LINE   START               FINISH
output_txc_45486m.xml           486   North Station       Friswell Place
SVRAYAO486-20121008-22264.xml   486   Dunoon              Inveraray
SVRGMB04860-20120103-5774.xml   486   BURY                RADCLIFFE
SVRYNAO486-20120217-44588.xml   486   Selby Bus Stn       Pollington Circular
  • 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-18T04:54:40+00:00Added an answer on June 18, 2026 at 4:54 am

    You can use GroupBy then get the first element of each group.

    var routes = (from txcalllines in db.TxcAllLines
                  where txcalllines.LineName == searchString
                  group txcalllines by new { txcalllines.Start, txcalllines.Finish } into g  // Groups the txcalllines by the pair (Start, Finish)
                  select g.First());  // Gets the first intem of the group
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm struggling to find the answer to this. I have only been using CakePHP
Ive been looking for this answer for hours, but I cant find it. I
I've been struggling to find a solution to achieve this. I have an HTML
I've been struggling with this for a while and have yet to find an
Hey I've been struggling with this whole day, and I can't find the answer
I've been struggling with this problem for a while now, searching every possible solution.
I've been struggling on this thing for a week without being able to find
I've been struggling with this for a while. Basically, I want to have two
I've been struggling with this problem for a few hours and it is preventing
I've been struggling with this problem for two weeks now. I've searched all over

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.