top operator

top operator

Returns the first N records sorted by the specified columns.

Syntax

T | top NumberOfRows by Expression [asc | desc] [nulls first | nulls last]

Parameters

NameTypeRequiredDescription
TstringThe tabular input to sort.
NumberOfRowsintThe number of rows of T to return.
ExpressionstringThe scalar expression by which to sort.
asc or descstringControls whether the selection is from the "bottom" or "top" of the range. Default desc.
nulls first or nulls laststringControls whether null values appear at the "bottom" or "top" of the range. Default for asc is nulls first. Default for desc is nulls last.

[!TIP] top 5 by name is equivalent to the expression sort by name | take 5 both from semantic and performance perspectives.

Example

Show top three storms with most direct injuries.

[!div class="nextstepaction"] Run the query

StormEvents
| top 3 by InjuriesDirect

The below table shows only the relevant column. Run the query above to see more storm details for these events.

InjuriesDirect...
519...
422...
200...

See also

  • Use top-nested operator to produce hierarchical (nested) top results.