Search code examples
sqlhibernatejpql

jpql select into select


it is possible to use one select's results as a table for another(in other word: upper) select statement. is there equivalent in jpql

Here is my sample sql statements

 SELECT X.NAME, SLS.TOTAL AS BENEFIT 
 (SELECT * FROM PERSON) X
 INNER JOIN SALESMAN SLS ON SLS.PERSON_ID = X.ID

what is the equivalant this statement in jpql?


Solution

  • No, it is not possible. Subqueries can only be used in WHERE and HAVING clauses, as told in JPA 2.0 specification:

    Subqueries may be used in the WHERE or HAVING clause.[58]
    ...
    [58] Subqueries are restricted to the WHERE and HAVING clauses in this release. Support for subqueries in the FROM clause will be considered in a later release of this specification.

    Also in JPA 2.1 this has not been changed.