I am using ClientObjectModel (C#) to retreive data from a custom list, which is structured like this:


What i need is some kind of "select distinct" which retreives only the categories, without duplicates:

cat1; cat2; cat3;

Im not able to find a way with CAML, and iterating through all items is not an option (the list contains 6000 items, to load each of them is very slow). Is there any other way I dont know?

1 Answer 1


Literally CAML query even in SharePoint 2013 doesn't have distinct function you can use, however I find this code that can help you,

 protected void btn_binddropdown_Click(object sender, EventArgs e)
                SPList oList = SPContext.Current.Web.Lists["CAMLTEST"];
                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");
                ddl_names.DataSource = dtdistinct; 
                ddl_names.DataTextField = "Name";
                ddl_names.DataValueField = "Name";

            catch (Exception exe)
                Response.Write("Exception at btn_binddropdown_Click :" + exe);

enter image description here


If nothing works then you still have choice of Custom web services or use jQuery or JS to select distinct list items,


Possible to get distinct values from GetListItems?

How to retrieve distinct values with JavaScript Client Object Model

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.