with cte (id, type, data) as (
select st.id, st.type, st.data
from some_table st
where st.type in (1,2)
)
select ...
from other_table
join cte as t1 on t1.id = x.id and t1.type = 1
join cte as t2 on t2.id = x.id and t2.type = 2;
QSomeTable st = new QSomeTable("st");
QOtherTable ot = new QOtherTable("ot");
PathBuilder<Tuple> cte = new PathBuilder<>(Tuple.class, "cte");
PathBuilder<Tuple> cte2 = ?????
SQLQuery sqlQuery = factory.query()
.with(cte, st.id, st.type, st.data).as(
select(st.id, st.type, st.data).
from(st).
where(...)
).
select(...).
from(ot).
join(cte).on(ot.id.eq(cte.get(cte.id))).
join(cte2) ????
new PathBuilder<>(Tuple.class, "cte2").
Hi,
I don't work with SQL query, but I guess it's the same like with JPA. You just name the second alias differently:new PathBuilder<>(Tuple.class, "cte2").
And in select part you do the same you do in your raw select:
.join(cte2).on(ot.id.eq(cte2.id)) (do you need that get there?)
with cte (id, type, data) as (
...
)
select ...
from other_table
join cte on cte.id = x.id and cte.type = 1
join cte2 on cte2.id = x.id and cte2.type = 2;
Also I noticed, that original query has 2 conditions on each ON - so you actually probably want .on(ot.id.eq(cte2.id).and(cte2.type.eq(2))).