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