Partager via


ORDER BY Clause

The ORDER BY clause sorts the results based on the value of one or more columns you specify. Following is the syntax of the ORDER BY clause:

ORDER BY [INDIVIDUAL|ALL] <column> [<direction>] [,<column> [<direction>]]

The INDIVIDUAL and ALL options determine whether results based on vector properties are returned individually. For example, if there is one document, Lorem.docx, with the System.Author property as "Theresa;Paul" and another document, Ipsum.docx, with the System.Author property as "Paul", the query using the INDIVIDUAL keyword returns the Lorem.docx item twice:

Item Name Author
Ipsum.docx Paul
Lorem.docx Paul
Lorem.docx Theresa

nbsp;

The column specifier must be a valid column. You can use the column specifier to refer to columns by the order that they appear in the query. The first column in the query is numbered 1. You can include more than one column in the ORDER BY clause, separated by commas.

The optional direction specifier can be either "ASC" for ascending (low to high) or "DESC" for descending (high to low). If you do not provide a direction specifier, the default, ascending, is used. If you specify more than one column, but do not specify all directions, the direction you specify last is applied to each column until you explicitly change the direction.

For example, in the following ORDER BY clause, the columns A, B, C, and G are sorted in ascending order, while columns D, E, and F are sorted in descending order.

ORDER BY A ASC, B, C, D DESC, E, F, G ASC