order By
Same as calling orderBy(column, null)
Adds an ORDER BY clause to the SELECT statement to sort the result set.
This function sorts the rows returned by the query based on the values in a specified column. By default, the sorting order is ascending (ASC). You can specify descending order (DESC) using the sort parameter.
This overload is for sorting by a single column. To sort by multiple columns with different sort orders, use the overload that accepts OrderColumn instances.
Example
// Selects all employees and orders them by their last name.
val ascendingCursor =
Employees
.select()
.orderBy(Employees.lastName) // Sort not applied
.execute()
// Selects all employees and orders them by their age in descending order.
val descendingCursor =
Employees
.select()
.orderBy(Employees.age, Sort.DESC)
.execute()Return
The SelectStatement instance, allowing for further chaining of query-building methods.
Author
MOHAMMAD AZIM ANSARI
Parameters
The KQLiteColumn to sort the result set by.
See also
Adds an ORDER BY clause to the SELECT statement to sort the result set by one or more columns, each with its own specific sorting order.
This overload is designed for complex sorting scenarios where you need to specify different sort directions (ascending/descending) for multiple columns. You achieve this by wrapping each column and its desired sort order in an OrderColumn object.
Example
// Selects employees, ordering them first by department ID in ascending order,
// and then by salary in descending order within each department.
val cursor =
Employees
.select()
.orderBy(
orderColumn1 = OrderColumn(Employees.departmentId, null, Sort.ASC),
orderColumn2 = OrderColumn(Employees.salary, null, Sort.DESC)
)
.execute()Return
The SelectStatement instance, allowing for further chaining of query-building methods.
Author
MOHAMMAD AZIM ANSARI
Parameters
The primary OrderColumn defining the first level of sorting.
An optional secondary OrderColumn for the second level of sorting.