Use distinct in a query with active objects

Alejandro Conde Carrillo
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 10, 2013

How should I use the SQL clause DISTINCT in an active objects query?

I have tried with something like this:

myVar = ao.find(MyClass.class, Query.select("FieldName").distinct());

but that command gets all rows, not only the distinct FieldNames.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

8 votes
Answer accepted
Alejandro Conde Carrillo
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 13, 2013

My problem was that I was using distinct with a count query.

ao.count(MyClass.class, Query.select("FieldName").distinct());

This translates in the SQL:

SELECT DISTINCT COUNT(*) FROM TABLE_NAME

To be able to get the row count using the DISTINCT clause, I had to do:

ao.find(MyClass.class, Query.select("FieldName").distinct()).lenght

Paul Pasler
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
July 29, 2018

Hmm, this throws an SQL Error if 'FieldName' differs from the `ID` field

java.sql.SQLSyntaxErrorException: incompatible data type in conversion: from SQL type VARCHAR to java.lang.Long, value: fieldValue
1 vote
Vincent Kopa _Ovyka_ January 19, 2015

a bug currently prohibits the usage of this feature, but Alex's answer is the right one

https://ecosystem.atlassian.net/browse/AO-398

TAGS
AUG Leaders

Atlassian Community Events