Hope to have something like sql GROUP BY or SELECT DISTINCT锛宼hanks.
Can you give some examples for your use cases? E.g. would you like to select a single value or multiple ones?
@greenrobot
For example, I need to query songs by the singer or album classification database, or I need to classify APP users according to a different value, but the query value is uncertain
@greenrobot this is an example :
for this sample data :
| id | title | date |
|-- | ---- | --- |
| 1 | item1 | 2017/10/01 |
| 2 | item2 | 2017/10/02 |
| 3 | item3 | 2017/10/04 |
| 4 | item2 | 2017/10/06 |
| 5 | item4 | 2017/10/07 |
| 6 | item1 | 2017/10/08 |
if we want DISTINCT title, result data must be :
| id | title | date |
|-- | ---- | --- |
| 1 | item1 | 2017/10/01 |
| 2 | item2 | 2017/10/02 |
| 3 | item3 | 2017/10/04 |
| 5 | item4 | 2017/10/07 |
@DJafari Would you be interested in only the title property, or would you want to have full objects as a result?
@greenrobot i updated my sample, because in objectbox can not possible to select fields, sure it must return full object but unique depends on distinct field
I have a need for something like GROUP BY, too, as I want to deduplicate a list of clicked offers by their external offer-id's (every offer can be clicked multiple times and every click has to be recorded).
I think to accomodate most needs, something like DISTINCT could be implemented like this:
String[] Query.distinctStrings(Property property);
long[] Query.distinctLongs(Property property);
float[] Query.distinctFloats(Property property);
double[] Query.distinctDoubles(Property property);
Whereas something like GROUP BY could be implemented like this:
QueryBuilder<T> QueryBuilder.groupBy(Property property);
Of course, the question would be, how the groups would be represented within the resulting collection (maybe something like List<List<T>>?), or if the groups would simply be flattened e.g. to their first item to keep the result as a List<T>.
Hi @DJafari did you found the solution for your question
I'm in line with @ajans suggestions.
Would something like String[] Query.distinctStrings(Property property); (and a variante for int, long, ...) do the trick for most of you?
Seems to have gone a bit quiet here, but I am still looking for this kind of functionality and what @ajans and @greenrobot have described above would be great!
+1 here
This is deployed via version 1.4.0-RC - please check it out.
Usage: Call the new Query.property method to get a PropertyQuery object. Here, you can config via methods distinct() and unique() before you call one of the find... methods to get primitive results.
Hi @greenrobot , @DJafari & @vishnupriyaanil did you find any solution to get object using distinct()
@greenrobot Wouldn't that be more helpful if we got the objects instead of the property?
Most helpful comment
@greenrobot this is an example :
for this sample data :
| id | title | date |
|-- | ---- | --- |
| 1 | item1 | 2017/10/01 |
| 2 | item2 | 2017/10/02 |
| 3 | item3 | 2017/10/04 |
| 4 | item2 | 2017/10/06 |
| 5 | item4 | 2017/10/07 |
| 6 | item1 | 2017/10/08 |
if we want
DISTINCT title, result data must be :| id | title | date |
|-- | ---- | --- |
| 1 | item1 | 2017/10/01 |
| 2 | item2 | 2017/10/02 |
| 3 | item3 | 2017/10/04 |
| 5 | item4 | 2017/10/07 |