CAML GroupBy usage when querying a list using the SPQuery or SPSiteDataQuery object

camlsharepoint

I'm not sure how to use the GroupBy clause when querying a list. The SPListItemCollection or datatable looks exactly the same regardless of the groupby clause.

SPQuery query = new SPQuery();
query.Query = "<GroupBy><FieldRef Name=\"Area\"/></GroupBy>";

DataTable result = list.GetItems(query).GetDataTable();

// result.Rows.Count = Same as ungrouped query 

Is GroupBy only supported by Lists.asmx webservice?

Found a reference on MS Social which suggests it's not supported on the SPSiteDataQuery object http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/ab8df6f5-35a0-401e-88cb-3eb31362bf0c/

Best Answer

I believe that clause is more related to how the grouping will be displayed in the UI. As far as the data returned goes, you might/should get some sorting but that's about it.

Regarding the UI, there is the GroupLimit element which limits how many groups are returned. There is also the Collapse element which has no meaning when used with SPQuery.

How were you hoping the data would be different?

Related Topic