JPA-从一栏中获得独特的价值 [英] JPA - getting distinct value from one column

查看:133
本文介绍了JPA-从一栏中获得独特的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个几乎没有字段的实体.其中之一是城市名称.现在,我想从该表中获取所有不同城市的列表.我该如何存档.我尝试使用DISTINCT关键字,但无效.

I have an entity that has few fields. One of them is city name. Now I want to get list of all distinct cities from that table. How can I archive that. I tried using DISTINCT keyword, but it doesn't work.

我使用Hibernate作为JPA提供程序,但我想在纯JPA查询中获取它.

I'm using Hibernate as JPA provider but I would like to get it in pure JPA Query.

推荐答案

您是否尝试过:

SELECT DISTINCT t.city FROM MyTable t

这篇关于JPA-从一栏中获得独特的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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