2013-09-16 14:49:36 -07:00
---
2013-09-26 18:22:28 -05:00
layout: doc_page
2013-09-16 14:49:36 -07:00
---
2014-01-16 15:37:07 -08:00
# Sort groupBy Query Results
2014-05-29 10:19:11 -07:00
The limitSpec field provides the functionality to sort and limit the set of results from a groupBy query. If you group by a single dimension and are ordering by a single metric, we highly recommend using [TopN Queries ](TopNQuery.html ) instead. The performance will be substantially better. Available options are:
2013-09-13 17:20:39 -05:00
### DefaultLimitSpec
2013-09-27 19:08:34 -05:00
The default limit spec takes a limit and the list of columns to do an orderBy operation over. The grammar is:
2013-09-13 17:20:39 -05:00
2013-09-27 19:08:34 -05:00
```json
{
"type" : "default",
"limit" : < integer_value > ,
"columns" : [list of OrderByColumnSpec],
}
```
2013-09-13 17:20:39 -05:00
#### OrderByColumnSpec
2014-10-28 10:38:21 -07:00
OrderByColumnSpecs indicate how to do order by operations. Each order-by condition can be a `jsonString` or a map of the following form:
2013-09-13 17:20:39 -05:00
2013-09-27 19:08:34 -05:00
```json
{
2014-10-28 10:38:21 -07:00
"dimension" : "< Any dimension or metric name > ",
"direction" : < "ascending"|"descending">
2013-09-27 19:08:34 -05:00
}
```
2014-10-28 10:38:21 -07:00
If only the dimension is provided (as a JSON string), the default order-by is ascending.