orderBy

abstract fun orderBy(column: KQLiteColumn<*>): UpdateStatement<T>

Adds an ORDER BY clause to the UPDATE statement for single column and default sorting.


abstract fun orderBy(column: KQLiteColumn<*>, sort: Sort?): UpdateStatement<T>

Adds an ORDER BY clause to the UPDATE statement.

This is typically used in conjunction with a LIMIT clause to control which rows are updated when the set of rows matching the WHERE clause is larger than the limit. The ORDER BY clause determines the order in which rows are considered for the update.

Note: The ORDER BY clause in an UPDATE statement is a non-standard SQLite extension.

Example

// Update the oldest 5 pending orders to 'processing'.
Orders
.update {
it.status.bind("processing")
}.where {
it.status EQ "pending"
}.orderBy(
Orders.orderDate,
sort = Sort.ASC
).limit(5)
.execute()

Return

The UpdateStatement instance for further chaining.

Author

MOHAMMAD AZIM ANSARI

Parameters

column

The KQLiteColumn to sort the rows by.

sort

The sorting order (Sort.ASC for ascending or Sort.DESC for descending). If null, the default database sort order is used (typically ascending).

See also


abstract fun orderBy(column: OrderColumn): UpdateStatement<T>

Adds an ORDER BY clause to the UPDATE statement using OrderColumn objects. Same as calling orderBy(column, null)


abstract fun orderBy(orderColumn1: OrderColumn, orderColumn2: OrderColumn?): UpdateStatement<T>

Adds an ORDER BY clause to the UPDATE statement using one or more OrderColumn objects.

This overload is useful for sorting by multiple columns, each with its own sorting direction or nulls handling. It is typically used with a LIMIT clause to control which rows are updated.

Note: The ORDER BY clause in an UPDATE statement is a non-standard SQLite extension.

Example

// Update the top 10 employees, prioritizing those with a higher bonus,
// and then by their hire date in descending order.
Employees
.update {
it.reviewStatus.bind("Completed")
}.where {
it.reviewStatus EQ "Pending"
}.orderBy(
OrderColumn(Employees.bonus, null, Sort.DESC, Nulls.FIRST),
OrderColumn(Employees.hireDate, null, Sort.DESC)
).limit(10)
.execute()

Return

The UpdateStatement instance for further chaining.

Author

MOHAMMAD AZIM ANSARI

Parameters

orderColumn1

The primary OrderColumn for sorting.

orderColumn2

An optional secondary OrderColumn for sorting. To sort by more than two columns, nest OrderColumn instances.

See also