我如何在JPQL内部加入子查询 [英] How can i inner join a subquery in JPQL

查看:109
本文介绍了我如何在JPQL内部加入子查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于MySQL查询,我需要一个JPQL:

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'

推荐答案

您的查询似乎很病理,也许说出您要查询的结果是什么,并包括对象模型.

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

通常,JPQL在from子句中不支持子选择,因此您的查询不能直接转换为JPQL.

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

您总是可以将其作为JPA本机SQL查询执行,因为您似乎比JPQL熟悉SQL.

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

这篇关于我如何在JPQL内部加入子查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆