Skip to main content

Joins

Inner Join

CustomerTable
.innerJoin(ShopTable, ShopTable.id eq CustomerTable.shop)
.perform(db)

Left and right join

CustomerTable
.leftJoin(ShopTable, ShopTable.id eq CustomerTable.shop)
.perform(db)

CustomerTable
.rightJoin(ShopTable, ShopTable.id eq CustomerTable.shop)
.perform(db)

Cross join

ShopTable
.crossJoin(CustomerTable)
.perform(db)

Self-join with alias

val alias = alias()

val row = ShopTable
.innerJoin(ShopTable.as_(alias), alias[ShopTable.id] eq groceryStoreId)
.where(ShopTable.id eq hardwareStoreId)
.perform(db)
.single()

check("Helen's Hardware" == row[ShopTable.name])
check("24 Hr Groceries" == row[alias[ShopTable.name]])