Search code examples
jpqlopenjpa

JPQL JOINS with nested SELECT


Can I do something like this on JPQL?

SELECT NEW com.MyDTO(p.a, p.b, q.c, q.d)
FROM
(SELECT r.* FROM MyDTO1 r ) p
LEFT OUTER JOIN
(SELECT s.* FROM MyDTO2 s ) q
ON p.x = q.y 

or similar? (Above query has mixed with native and JPQL, so don't misunderstand)

I'm having a problem with this part I think.

FROM
(SELECT r.* FROM MyDTO1 r ) p

When I'm trying to execute I'm getting this error.

Exception Description: Syntax error parsing the query [.....], unexpected token [(]

Thank you!


Solution

  • No, you can't. Quote from the documentation:

    Note that HQL subqueries can occur only in the select or where clauses.