How can I retrieve all elements in a List ignoring duplicate entries
So if List A contains:
Employee A
Employee A
Employee B
Employee B
Employee C
Employee D
Employee E
I want to get
Employee A
Employee B
Employee C
Employee D
Employee E
How can I retrieve all elements in a List ignoring duplicate entries
So if List A contains:
Employee A
Employee A
Employee B
Employee B
Employee C
Employee D
Employee E
I want to get
Employee A
Employee B
Employee C
Employee D
Employee E
Daniel,
The Distinct operation isn't available in CAML Queries.. However, there are different things you can try.. You can use LINQ to get distinct results:
var distinctItems = (from SPListItem item in items select item["EmployeeName"]).Distinct().ToArray();
Or convert your results to DataView and do something like:
SPList oList = SPContext.Current.Web.Lists["ListName"];
SPQuery query = new SPQuery();
query.Query = "<OrderBy><FieldRef Name='Name' /></OrderBy>";
DataTable dtcamltest = oList.GetItems(query).GetDataTable();
DataView dtview = new DataView(dtcamltest);
DataTable dtdistinct = dtview.ToTable(true, "Name");
CAML query schema for SP2013 doesn't contain distinct still, so I think it is not changed. However you may group results in CAML (using GroupBy element) - it will produce groups for distinct values of the field.