JPQL Subqueries
A subquery can be used in most conditional expressions and can appear on either the left or right side of an expression.
El siguiente ejemplo obtiene a través de un subquery la pregunta con el alias máximo:
select q.alias from Question q where q.alias = (select max(q1.alias) from Question q1)
El primer query se ejecuta solo cuando el subquery trae resultados:
select q.options as opt from Question q where exists (select 1 from Question q1 where q1.alias='q1')