Alias Table
Represents a table with an alias in a SQL query.
This class is used to create a temporary, alternative name for a table, which is particularly useful in JOIN operations or when a query involves the same table multiple times. It allows columns from the original table to be referenced via the alias.
Example
// Table self join example
val m = Employees AS "m"
val e = Employees AS "e"
val manager =
m[Employees.firstName]
.CONCAT(" ")
.CONCAT(m[Employees.lastName]) AS "Manager"
val directReport =
e[Employees.firstName]
.CONCAT(" ")
.CONCAT(e[Employees.lastName]) AS "Direct report"
val cursor =
e
.select(
manager,
directReport,
).join(m, JoinType.INNER_JOIN)
.on(m[Employees.employeeId], e[Employees.reportsTo].notNull())
.where {
LENGTH(manager) GT 4
}.orderBy(manager)
.execute()
val data =
cursor
.asSequence()
.map { it[manager] to it[directReport] }
.toList()
cursor.close()Content copied to clipboard
Author
MOHAMMAD AZIM ANSARI
Parameters
original
The original KQLiteTable being aliased.
tbl Alias
The alias String for the table.