2013-09-16 17:49:36 -04:00
---
2013-09-26 19:22:28 -04:00
layout: doc_page
2013-09-16 17:49:36 -04:00
---
2014-01-16 18:37:07 -05:00
# Sort groupBy Query Results
2014-05-29 13:19:11 -04: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 18:20:39 -04:00
### DefaultLimitSpec
2013-09-27 20:08:34 -04: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 18:20:39 -04:00
2013-09-27 20:08:34 -04:00
```json
{
"type" : "default",
"limit" : < integer_value > ,
"columns" : [list of OrderByColumnSpec],
}
```
2013-09-13 18:20:39 -04:00
#### OrderByColumnSpec
2014-10-28 13:38:21 -04: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 18:20:39 -04:00
2013-09-27 20:08:34 -04:00
```json
{
2014-10-28 13:38:21 -04:00
"dimension" : "< Any dimension or metric name > ",
"direction" : < "ascending"|"descending">
2013-09-27 20:08:34 -04:00
}
```
2014-10-28 13:38:21 -04:00
If only the dimension is provided (as a JSON string), the default order-by is ascending.