I'm new to QueryDSL and would to be able to assemble a query with multiple columns in the WHERE-IN clause, like the following query:
selec T1.COL1, T1.COL2, .... T1.COL10
from T1
where (T1.COL1, T1.COL2) IN (select T2.COL1, T2.COL2 from T2 WHERE T2.COL3='a' AND T2.COL4='b')
I have the part of the main query down:
List<Tuple> result = queryFactory.select(t1.col,...,t1.col10)
.from(t1)
.where(???) // This is the part I'm missing
.fetch();
But I don't know how to implement the where clause. How can this be done in QueryDSL?
Thanks in advance!
I had the same problem and it took me a day to find the solution to it. You can use Expressions.list() to specify more than one column for the in clause.
So here's what you should have in your where() clause:
Expressions.list(t1.col1, t1.col2).in(
JPAExpressions.select(t2.col1, t2.col2)
.from(t2)
.where(...)
)
Hope it helps someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With