实体管理器-创建查询-嵌套选择

时间:2019-05-19 13:07:44

标签: java sql hibernate jpa h2

我正在尝试执行下一个:

em.createQuery("SELECT processId FROM (SELECT processId FROM table_name WHERE processName like '%abcaccz%')")

但是我得到了:

Method threw 'java.lang.IllegalArgumentException' exception.
unexpected token: ( near line 1, column 23

这里缺少什么? (这在我的数据库客户区域中起作用。)

1 个答案:

答案 0 :(得分:1)

正确的语法是:

em.createQuery("SELECT processId = (SELECT processId FROM table_name WHERE processName like '%abcaccz%') FROM table_name")

或:

em.createQuery("
  SELECT processId
    FROM table_name
    WHERE processId IN (SELECT processId
                           FROM table_name
                           WHERE processName like '%abcaccz%')")