Order By



ORDER BY sorts the results, ascending (ASC, the default) or descending (DESC), by one or more fields, expressions or aggregate functions.

Notes on result limiters

When using Top or Offset, the ORDER BY is applied before the rows are limited.


round-pushpin Orders the words ascending by Text.
SELECT Id, Text, LanguageId FROM WordList:Word WHERE Text LIKE 'Summar%' ORDER BY Text

round-pushpin Orders by LanguageId ascending and then by Text descending.
SELECT
    Id, Text, LanguageId
FROM
    WordList:Word
ORDER BY
    LanguageId ASC,
    Text DESC

round-pushpin Orders by an expression.
SELECT Text FROM WordList:Word WHERE LanguageId = 1 ORDER BY Length(Text) DESC

round-pushpin Orders groups by an aggregate.
SELECT LanguageId, Count(0) as Words FROM WordList:Word GROUP BY LanguageId ORDER BY Count(0) DESC




SQL :: Aggregate Functions
Aggregate functions compute one value from a group of rows.
SQL :: Avg
Returns the average (arithmetic mean) of the values in each group.
SQL :: Count
Returns the number of values in each group. Count(0) and Count(*) count the documents in each group.
SQL :: CountDistinct
Returns the number of distinct values in each group. Values are compared without regard to case unless caseSensitive is true.
SQL :: Distinct
Removes duplicate rows from the results of a SELECT.
SQL :: GeometricMean
Returns the geometric mean of the values in each group: the nth root of their product. Useful for growth rates and ratios.
SQL :: Group By
Group by collapses a result set into one row per distinct set of values.
SQL :: Keywords
A breakdown of all of the statements and keywords supported by the query processor.
SQL :: Max
Returns the largest numeric value in each group. Use MaxString for text.
SQL :: MaxString
Returns the alphabetically largest value in each group.