from

abstract fun from(selectStatement: () -> SelectStatement<*>): UpdateStatement<T>

Adds a FROM clause to the UPDATE statement, allowing updates based on values from another query.

This is useful for UPDATE FROM constructs, where rows in the target table are updated using data from a SELECT statement. The WHERE clause can then reference columns from both the target table and the result of the SELECT statement.

This feature is supported on SQLite version 3.33.0 and newer.

Example

    class Daily : KQLiteTable("daily") {
val qty = intColumn("qty")
val itemId = longColumn("item_id")
}

val daily = Daily()

Inventory
.update {
it.quantity.bind(it.quantity - daily.qty.notNull())
}.from {
select(
SUM(Sales.quantitySold) AS "qty",
Sales.itemId,
).from(Sales)
.groupBy(Sales.itemId) AS "daily"
}.where {
Inventory.itemId EQ daily.itemId.notNull()
}.execute()

Return

The UpdateStatement instance for further chaining.

Author

MOHAMMAD AZIM ANSARI

Parameters

selectStatement

A lambda function that returns a SelectStatement. This statement provides the source data for the update.

See also