I cannot comment on how to do this in C # / VB with a data table, but if you can move all this into SQL, your query will look like this:
declare @t table (ID int, Name varchar(10), LastName varchar(10), Age int) insert into @t values (1, 'Bart' , 'Simpson', 10 ) insert into @t values (2, 'Lisa', 'Simpson' , 8 ) insert into @t values (3, 'Bart', 'Simpson' , 10 ) insert into @t values (4, 'Ned', 'Flanders' , 40 ) insert into @t values (5 , 'Bart', 'Simpson' , 10 ) select t.*, (select min(ID) as ID from @t t2 where t2.Name = t.Name and t2.LastName = t.LastName and t2.id < t.id) from @tt
Here I have defined a table for demonstration purposes. I suppose you could translate this to LINQ.
source share