SpringData : is it possible to have subqueries in the Query annotation?

No, it is not possible to have subquery in the select clause in JPQL query.

JPQL supports subqueries in WHERE and HAVING clauses. It can be (at least) part of ANY, SOME, ALL, IN, EXIST expressions, and of course it can be used normal conditional expressions:

SELECT a
FROM A a
WHERE a.val = (SELECT b.someval 
               FROM B b 
               WHERE b.someotherval=3)

Leave a Comment