Skip to main content

From

Definition

The from methods allows you to add the FROM clause to the query.

Available methods

1. from(KTable kTable)

  • kTable: is the table which will be added to FROM clause.

2. from(KRaw kRaw):

  • kRaw: is a raw content which will be added in the FROM clause.

3. from(KCommonTableExpressionFilled kCommonTableExpressionFilled)

  • kCommonTableExpressionFilled: is a Common Table Expressions or CTE that will be added to the FROM clause.

Method hierarchy

The from method can be used right after the following methods:

and the subsequent methods that can be called are:

Example: KTable (generated.metadata)

Java code:

k
.select(
APP_USER.EMAIL
)
.from(APP_USER)
.multiple();

SQL generated:

SELECT au.email
FROM app_user au

Parameters:

  • None

Example: KTable (from subquery)

Java code:

final KTable kTableUsers =
k
.select(APP_USER.ID, APP_USER.FIRST_NAME, APP_USER.LAST_NAME)
.from(APP_USER)
.as("us");

k
.select(
kTableUsers.c("id"),
kTableUsers.c("first_name"),
kTableUsers.c("last_name")
)
.from(kTableUsers)
.multiple();

SQL generated:

SELECT us.id, us.first_name, us.last_name
FROM (
SELECT au.id, au.first_name, au.last_name
FROM app_user au
) us

Parameters:

  • None

Example: KTable (from subquery with custom aliases in a tuple)

Java code:

final KTable kTableUsers =
k
.select(APP_USER.ID, APP_USER.FIRST_NAME, APP_USER.LAST_NAME)
.from(APP_USER)
.as("us", "a", "b", "c");

k
.select(
kTableUsers.c("a"),
kTableUsers.c("b"),
kTableUsers.c("c")
)
.from(kTableUsers)
.multiple();

SQL generated:

SELECT us.a, us.b, us.c
FROM (
SELECT au.id, au.first_name, au.last_name
FROM app_user au
) us (a, b, c)

Parameters:

  • None

Example: KRaw

Java code:

k
.select(
APP_USER.EMAIL
)
.from(raw("app_user au"))
.multiple();

SQL generated:

SELECT au.email
FROM app_user au

Parameters:

  • None

Example: KCommonTableExpressionFilled

Java code:

final KGenericQuery kQueryNewUsers =
k
.select(APP_USER.ID, APP_USER.FIRST_NAME)
.from(APP_USER)
.where(APP_USER.CREATED_AT.gt(LocalDateTime.now().minusDays(1)));

final KCommonTableExpressionFilled cteNewUsers =
cte("new_users")
.columns("id", "first_name")
.as(kQueryNewUsers, "nu");

k
.with(cteNewUsers)
.select(cteNewUsers.c("id"), cteNewUsers.c("first_name"))
.from(cteNewUsers)
.multiple();

SQL generated:

WITH new_users (id, first_name) AS (
SELECT au.id, au.first_name
FROM app_user au
WHERE au.created_at > ?1
)
SELECT nu.id, nu.first_name
FROM new_users nu

Parameters:

  • ?1: 2022-12-29T09:40:53.510482