Sort query results
Some APIs in Workspaces make use of an optional "sorts"
attribute in the JSON Query object. If specified, the results returned will be ordered according to the string provided. By default, results are ordered by id
.
APIs that do not have the "sorts"
attribute are ordered by id
.
Sort Strings
Sorting is defined by providing a list of sort strings in the format "ATTRIBUTE ORDER".
Item | Description |
---|---|
attribute | Required. A supported sort criteria attribute. The available sort criteria attributes are specific to each API, and documented for each API that supports sorting. |
order | Required. The order to return records, either ascending or descending. Values: "asc" , "desc" ."asc" is short for "ascending", while "desc" is short for descending. |
Specify multiple "sorts"
items to order results based on two or more attributes.
Examples
Single attribute sort
This example orders Txn
records by submitKey
(a supported attribute in the POST Txn Query) in ascending order.
{
"fetchLimit": 100,
...
"sorts": [
"submitKey asc"
]
}
The equivalent pseudo-query is:
SELECT * FROM
SUBMISSIONS S
ORDER BY S.submitKey ASC
Multiple attribute sort
This example illustrates Txn
records ordered first by spaceName
in ascending order then by clientCode
in descending order.
{
"fetchLimit": 100,
...
"sorts": [
"spaceName asc",
"clientCode desc"
]
}
Records are returned, ordered by spaceName
in alphabetical (asc
) order. Records that have the same spaceName
are orderd by clientCode
in reverse alphabetical (desc
) order. For example:
# | clientCode | spaceName |
---|---|---|
1 | client1 | Web-Plugin |
2 | ZClient | Workspace |
3 | testClient | Workspace |
4 | client1 | Workspace |
The equivalent pseudo-query is:
SELECT * FROM
SUBMISSIONS S
ORDER BY S.spaceName ASC, S.clientCode DESC