我想根据属性获得不同的结果,但在选择中返回 id,因为我将在子查询中使用它。
例如
(List<Article>) session.createQuery("from Article a where a.id in (select distinct a2.title from article a2 where a2.body = :body");
setString("body", "")
.list();
关键部分是子查询,我想返回id,而不是a2.title属性。 这可以吗?
(表 Article 有重复项,所以我只想返回其中任何一个,只要 body = ""就没关系)。
最佳答案
如果您不关心返回哪一行,您可以将子查询更改为:
select MIN(a2.id) from article a2 where a2.body = :body
这将返回 article
中 body
匹配的最低 id
。
关于java - 如何获得不同的结果,但在选择中返回另一列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2028824/