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.
Community moderators have prevented the ability to post new answers.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
a bug currently prohibits the usage of this feature, but Alex's answer is the right one
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.