EMZETT.
Login

Ascending and descending

In short: Ascending means sorted upward (small to large, A to Z), descending means downward (large to small, Z to A).

In more detail: In SQL this is ORDER BY column ASC or DESC. Without a specification ascending applies. In programming languages the direction is controlled by a comparison (comparator) or a parameter.

In detail

  • SQL: SELECT * FROM customers ORDER BY name ASC, age DESC;
  • Java: list.sort(Comparator.naturalOrder()) or Comparator.reverseOrder().
  • Python: sorted(l) and sorted(l, reverse=True).
  • JavaScript: a.sort((x, y) => x - y) ascending, y - x descending (without a function sort() sorts as text).
  • Strings: order by character code or language rules (collation).
  • Stable: a stable algorithm keeps the order of equal elements, see Sorting.

See also: Array, Sorting