Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multicolumn WHERE-IN clause in QueryDSL

Tags:

querydsl

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!

like image 972
Tamara Aviv Avatar asked Jun 14 '16 19:06

Tamara Aviv


1 Answers

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.

like image 71
Timi Avatar answered Oct 02 '22 21:10

Timi