search sharepoint list column item having same value

258 Views Asked by At

Suppose i have a sharepoint list. Please find below details

Listname="NameData"


Name        ModifiedDate  Place

keshav      19/12/2015    A
madhav      19/11/2015    B
keshav      19/10/2015    C
madhav      19/10/2015    D
Ram         19/10/2015    E

I just wants to get all column values like Name,Modified etc if

Name is duplicate like keshav in name column then it should fetch only those row values in which keshav modified date is latest for example in above Case name column keshav has duplicate value then SPQuery should featch column value as (Name:keshav,Modified:19/12/2015,Place:A) as it has latest modified date. If there is no duplicate column value then it should same value. Please provide me Spquery for above case. Thanks

1

There are 1 best solutions below

1
On

So i was able to answer my own question after one month of struggle.

Please find below code using link query.

   SPList lstICSSDocuments = web.Lists.TryGetList("YourListName");

  List<SPListItem> filtered_List_Item = (from SPListItem item in lstICSSDocuments

                     group item by item["Name"].ToString() into grp

                     select grp.OrderByDescending(g => g["ModifiedDate"]).First()).ToList();