Berserk Docs
Tabular OperatorsFilter Operators

top

Returns the top N rows sorted by the specified columns.

Returns the top N rows sorted by the specified columns. More memory-efficient than sort+take for large datasets.

Syntax

top N by column [asc|desc] [nulls first|last], ...

Return top N rows sorted by columns with optional null placement. Default sort order is descending (desc).

Parameters

NameDescription
countMaximum number of rows to return
columnColumn or expression to sort by. Default order is descending if not specified.
nulls firstlast

Examples

Example 1

datatable(raid:string, loot_silver:long, monastery:string)[
  "793 Lindisfarne", 500, "Lindisfarne",
  "845 Paris", 7000, "Saint-Germain",
  "860 Winchester", 300, "Winchester",
  "866 York", 1200, "York Minster",
  "911 Normandy", 4000, "Rouen"
]
| top 3 by loot_silver
raid (string)loot_silver (long)monastery (string)
845 Paris7000Saint-Germain
866 York1200York Minster
911 Normandy4000Rouen

Example 2

datatable(warrior:string, battles:long)[
  "Ragnar", 30,
  "Bjorn", 15,
  "Ivar", 22,
  "Lagertha", 18,
  "Harald", 25
]
| top 2 by battles asc
warrior (string)battles (long)
Bjorn15
Lagertha18

On this page