realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

DISTINCT

Open iflatness opened this issue 11 years ago • 7 comments

In my usage, there are various times where I only want one out of a set of objects that share a value of a field - much like the 'DISTINCT' clause in SQL. For exampe, with the items

name logInTime
Bill 1426270572
Mark 1426272004
Mark 1426273505
Mark 1426274666
Sally 1426268301
Sally 1426271123

in the table 'User', realm.where(User.class).distinct("name").findAll() would return 3 items (one for 'Mark', one for 'Bill', and one for 'Sally'). With it like this, which 'Mark' and which 'Sally' is undefined - presumably the first one Realm finds.

A potential advanced aspect of this would be to select which of the rows to return. realm.where(User.class).distinct("name", "logInTime", false).findAll() would return (Bill, 1426270572), (Mark, 1426274666), (Sally,1426271123), or only having the first discovered in an sorted RealmResult appear.

iflatness avatar Mar 13 '15 19:03 iflatness

The first part sounds very much like the DISTINCT keyword in SQL, is that correct? We actually have support for that in the core database, but it havn't been exposed yet in the Java query language.

The second part is harder to express in a succinct way, so it is a use case to consider, but it will most likely complicate the query language too much compared to how many people would actually use it.

cmelchior avatar Mar 16 '15 05:03 cmelchior

Right, don't know what I was thinking. Modified

iflatness avatar Mar 16 '15 18:03 iflatness

Do we have a timeline for this one? thanks!

kenticus avatar May 12 '15 22:05 kenticus

+1

mandrachek avatar Jun 01 '15 05:06 mandrachek

+1

EliasMazz avatar Aug 13 '15 13:08 EliasMazz

+1 :(

StErMi avatar Sep 28 '15 15:09 StErMi

As #1566 only implements Realm.distinct(), a new issue (#1568) is created for tracking RealmResults.distinct().

kneth avatar Oct 09 '15 13:10 kneth