在 LEFT JOIN hql 中进行子选择
Subselect in LEFT JOIN hql
我有一个查询在我的查询的 LEFT JOIN 子句中使用子选择
每次我 运行 查询它都会给出 org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: (
错误。 '(' 是我的子选择的左括号。
我的查询看起来是这样的:
SELECT a, b, c
FROM table1 as t1
INNER JOIN t1.table2 as t2
INNER JOIN t1.table3 as t3
INNER JOIN t3.table4 as t4
LEFT JOIN ( //<- this one gives the error
SELECT d, e, f
FROM table9 as t9
....
) as xx WITH xx.prop = t2.prop and xx.prop2 = t4.prop
WHERE t1.yy = true and t1.zz = '0'
GROUP BY t2.column
我在 sql 中有相同的查询,当我在 MySQL 中 运行 它时,它有效 returns 我需要的数据。当我使用 HQL 版本时,它会在 (
打开我的子查询时出错。
这种子查询在 HQL 中可行吗?我应该使用 SQL 吗?
如果是的话我做错了什么?
编辑:
我尝试将 WITH
更改为 ON
,它仍然给出相同的错误。
内部连接工作正常,因为这是在 Java 中配置自动匹配外键的 HQL,所以我不需要在每个连接上都使用 on/witch 子句。
EDIT2:
如果我评论左连接查询有效,所以不是缺少 on
或使用 with
而不是它给我带来了麻烦
当您加入 table 时,您需要使用 ON
关键字。
LEFT JOIN (
SELECT d, e, f
FROM table9 as t9
....
) as xx ON xx.prop = t2.prop and xx.prop2 = t4.prop
你还忘记了第二个 属性 的连接中的 =
。
编辑:
A subquery must be surrounded by parentheses (often by an SQL
aggregate function call). Even correlated subqueries (subqueries that
refer to an alias in the outer query) are allowed. Note that HQL
subqueries can occur only in the select or where clauses.
由此可见,在 from 子句中不能有子查询。
我有一个查询在我的查询的 LEFT JOIN 子句中使用子选择
每次我 运行 查询它都会给出 org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: (
错误。 '(' 是我的子选择的左括号。
我的查询看起来是这样的:
SELECT a, b, c
FROM table1 as t1
INNER JOIN t1.table2 as t2
INNER JOIN t1.table3 as t3
INNER JOIN t3.table4 as t4
LEFT JOIN ( //<- this one gives the error
SELECT d, e, f
FROM table9 as t9
....
) as xx WITH xx.prop = t2.prop and xx.prop2 = t4.prop
WHERE t1.yy = true and t1.zz = '0'
GROUP BY t2.column
我在 sql 中有相同的查询,当我在 MySQL 中 运行 它时,它有效 returns 我需要的数据。当我使用 HQL 版本时,它会在 (
打开我的子查询时出错。
这种子查询在 HQL 中可行吗?我应该使用 SQL 吗?
如果是的话我做错了什么?
编辑:
我尝试将 WITH
更改为 ON
,它仍然给出相同的错误。
内部连接工作正常,因为这是在 Java 中配置自动匹配外键的 HQL,所以我不需要在每个连接上都使用 on/witch 子句。
EDIT2:
如果我评论左连接查询有效,所以不是缺少 on
或使用 with
而不是它给我带来了麻烦
当您加入 table 时,您需要使用 ON
关键字。
LEFT JOIN (
SELECT d, e, f
FROM table9 as t9
....
) as xx ON xx.prop = t2.prop and xx.prop2 = t4.prop
你还忘记了第二个 属性 的连接中的 =
。
编辑:
A subquery must be surrounded by parentheses (often by an SQL aggregate function call). Even correlated subqueries (subqueries that refer to an alias in the outer query) are allowed. Note that HQL subqueries can occur only in the select or where clauses.
由此可见,在 from 子句中不能有子查询。