From a domain class instance in the database I want to get the last 20 updated records but distinct to a certain property, which in my case is color
. I've tried 3 different approaches but none seem to work the way I expected.
First approach:
def corridors = TerminKorridor.findAll([max:20, sort:'lastUpdated', order:"desc"]).color.unique();
works but doesn't return 20 entries
Second approach:
def corridors = corridorsCriteria.list{
distinct("color")
maxResults(20)
order("lastUpdated", "desc")
}
doesn't remove entries with same colors. Distinct doesn't work
Third approach:
def corridors = TerminKorridor.executeQuery("Select distinct a.color from TerminKorridor a order by a.lastUpdated desc",[max:20])
doesn't remove entries with same colors, distinct
doesn't work.