on

abstract fun <C> on(left: KQLiteColumn<C>, right: KQLiteColumn<C>): SelectStatement<T>

Same as calling on(left, right, JoinOp.EQ, null, null)


abstract fun <C> on(left: KQLiteColumn<C>, right: KQLiteColumn<C>, joinOp: JoinOp = JoinOp.EQ, and: Clause.() -> Unit? = null, or: Clause.() -> Unit? = null): SelectStatement<T>

Specifies the ON condition for a JOIN clause.

This function defines how two tables are related in a join operation by comparing columns. It supports standard comparison operators and allows for additional AND or OR conditions.

Example (Inner Join)

// SELECT * FROM Artists
// INNER JOIN Albums ON Artists.artistId = Albums.artistId
Artists
.select()
.join(Albums, JoinType.INNER_JOIN)
.on(Artists.artistId, Albums.artistId)
.execute()

Example (Inner Join with additional AND condition)

// Example with an additional AND condition
// SELECT * FROM Artists
// INNER JOIN Albums ON Artists.artistId = Albums.artistId AND Albums.year > 2000
Artists
.select()
.join(Albums, JoinType.INNER_JOIN)
.on(
Artists.artistId,
Albums.artistId,
and = {
Albums.year GT 2000
},
).execute()

Example (Join with < operator)

Artists
.select(Artists.artistName, Albums.title)
.join(Albums)
.on(Artists.artistId, Albums.artistId, JoinOp.LT)
.orderBy(Artists.artistName)
.limit(15, 10)
.execute(con)

Return

A SelectStatement that can be further modified (e.g., with WHERE, ORDER BY) or executed.

Author

MOHAMMAD AZIM ANSARI

Parameters

left

The column from the left table in the comparison.

right

The column from the right table in the comparison.

joinOp

The operator to use for the comparison (e.g., EQ, NEQ, GT). Defaults to JoinOp.EQ (=).

and

A lambda function to build an additional AND clause.

or

A lambda function to build an additional OR clause.

Type Parameters

C

The data type of the columns being compared.

See also