Join with subquery in Querydsl SQL 3.7.4

72 views
Skip to first unread message

Paul Woolley

unread,
Jan 30, 2018, 3:21:50 AM1/30/18
to Querydsl
Hi,

There's some SQL that I'd like to express using Querydsl SQL 3.7.4.  It involves having a subquery in both the from and the join parts of the SQL.  Like this...

select fields
from (
select fields
from some table
where some restrictions
) t1
full join (
select fields
from some other table
where some restrictions
) t2
on 
join conditions

I've done some searching within this group and stackoverflow and can see that joins on subqueries are not allowed with Querydsl JPA, and that there is some way to do this in Querydsl 4 using SQLExpressions.select, but I haven't found a definitive answer yet as to whether joining with a subquery is possible in Querydsl SQL 3.7.4.

Here is a contrived code example of what I was hoping to do with Querydsl:

SQLSubQuery main = new SQLSubQuery();
SQLSubQuery fromSubQuery = new SQLSubQuery().from().where();
SQLSubQuery joinSubQuery = new SQLSubQuery().from().where();
BooleanExpression joinConditions = BooleanTemplate.TRUE;
main.from(fromSubQuery.list(SQLExpressions.all))
.join(joinSubQuery.list(SQLExpressions.all)) // <-- This part does not compile
.on(joinConditions)
.list(SQLExpressions.all);

For reasons, upgrading to version 4 is not an option and the "main" must be an instance of SQLSubQuery also.

My experimentation so far is strongly suggesting that this is not possible, but if someone knows how to achieve this, then it is greatly appreciated.

Thank you,
  Paul.

Reply all
Reply to author
Forward
0 new messages