Sorts a query.

querySort(query, sortFunction) → returns boolean

Member Function Syntax


Argument Reference for the querySort function


Required: Yes
The query you want to sort


Required: Yes
CF 2016+ or Lucee a function with two arguments each corresponding to a query row. The function returns -1 if first row is less than second, 0 if equal, or 1 if first row is greater than second. Lucee 4.5+ accepts a column name to sort by instead of a function.


Required: No
Lucee 4.5+ Only supported on Lucee when second argument is a column name instead of a callback function.



Lucee also supports querySort(query, column_name [, direction]) syntax. As of it accepts a callback function. When called as a member function query.sort() is chainable.

Examples sample code invoking the querySort function

Sorting a query using sort member function

//build a query
news = queryNew("id,title",
    [ {"id":1,"title":"Dewey defeats Truman"}, {"id":2,"title":"Man walks on Moon"} ]);
//sort it
news.sort(function(rowA, rowB) { return compare(rowA.title, rowB.title); });
//dump it

Fork me on GitHub