sort.asciidoc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. [discrete]
  2. [[esql-sort]]
  3. === `SORT`
  4. **Syntax**
  5. [source,esql]
  6. ----
  7. SORT column1 [ASC/DESC][NULLS FIRST/NULLS LAST][, ..., columnN [ASC/DESC][NULLS FIRST/NULLS LAST]]
  8. ----
  9. *Parameters*
  10. `columnX`::
  11. The column to sort on.
  12. *Description*
  13. The `SORT` processing command sorts a table on one or more columns.
  14. The default sort order is ascending. Use `ASC` or `DESC` to specify an explicit
  15. sort order.
  16. Two rows with the same sort key are considered equal. You can provide additional
  17. sort expressions to act as tie breakers.
  18. Sorting on multivalued columns uses the lowest value when sorting ascending and
  19. the highest value when sorting descending.
  20. By default, `null` values are treated as being larger than any other value. With
  21. an ascending sort order, `null` values are sorted last, and with a descending
  22. sort order, `null` values are sorted first. You can change that by providing
  23. `NULLS FIRST` or `NULLS LAST`.
  24. *Examples*
  25. [source,esql]
  26. ----
  27. include::{esql-specs}/docs.csv-spec[tag=sort]
  28. ----
  29. Explicitly sorting in ascending order with `ASC`:
  30. [source,esql]
  31. ----
  32. include::{esql-specs}/docs.csv-spec[tag=sortDesc]
  33. ----
  34. Providing additional sort expressions to act as tie breakers:
  35. [source,esql]
  36. ----
  37. include::{esql-specs}/docs.csv-spec[tag=sortTie]
  38. ----
  39. Sorting `null` values first using `NULLS FIRST`:
  40. [source,esql]
  41. ----
  42. include::{esql-specs}/docs.csv-spec[tag=sortNullsFirst]
  43. ----