HQL: How to select all entities distinct by some column?

后端 未结 7 1282
被撕碎了的回忆
被撕碎了的回忆 2020-12-14 08:20



A simple question:
In this example I need to retrieve all objects, but these objects must have distinct msgFrom fields.
When I use

List&         


        
7条回答
  •  生来不讨喜
    2020-12-14 08:48

    Below is the sample query :

    select e from Message e 
    where e.msgFrom IN (select distinct m.msgFrom 
                          from Message m
                          WHERE m.msgTo = ? 
                          AND m.msgCheck = "0");
    

    Alternatively, you can also use Criteria API.

提交回复
热议问题