How can i inner join a subquery in JPQL

跟風遠走 提交于 2019-12-06 06:18:52

问题


I need a JPQL for the MySQL query:

SELECT * 
FROM table1 t1 
INNER JOIN table2 t2 
  ON t1.id = t2.table1.id 
INNER JOIN (SELECT * FROM table1 t3 
            INNER JOIN table2 t4 ON t3.id = t4.table1.id 
            WHERE t3.name = 'xxx') subTable 
  ON t1.number = subTable.number 
WHERE t1.number = '5' 
  AND id = '3'

回答1:


Your query seems quite pathological, perhaps say what result you are trying to query, and include your object model.

In general, JPQL does not support sub-selects in the from clause, so your query is not directly convertable to JPQL.

You can always just execute it as a JPA native SQL query, since you seem to be comfortable with SQL than JPQL.



来源:https://stackoverflow.com/questions/9906710/how-can-i-inner-join-a-subquery-in-jpql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!