Skip to content

Order By

Mathias Rangel Wulff edited this page Jun 12, 2015 · 4 revisions

Keyword ORDER BY

Syntax:

    SELECT ... ORDER BY expression1 [ASC|DESC], ...

You can specify order with keywords:

  • ASC - ascending (by default)
  • DESC - descending

Ascending:

    alasql('SELECT * FROM City ORDER BY Population');
    alasql('SELECT * FROM City ORDER BY Population ASC');

Descending:

    alasql('SELECT * FROM City ORDER BY Name DESC');

Number notation for ORDER BY

AlaSQL supports number notation for ORDER BY arguments:

    var data = [{a:2,b:20},{a:2,b:30},{a:3,b:10}];
    var res1 = alasql('SELECT a,b FROM ? ORDER BY 2,1',[data]);
    var res2 = alasql('SELECT a,b FROM ? ORDER BY 1 DESC,2 DESC',[data]);

See also: SELECT, [GROUP BY](Group By)

Clone this wiki locally