KaliMa KaliMa - 1 year ago 194
SQL Question

GreenDao, querying for a list of strings

Within my application I have an Entity / table that has a Name field (among several other fields). I want a list of Strings of all the unique names found in that table.

Right now the only thing I can think of is to load all the results into a list of entity objects, iterate over them, and store the names in a Set, and then convert this Set into a List.

It seems inefficient though. Does GreenDao support a feature like this natively or must all queries return Entity objects?

Answer Source

It doesn't support it natively. You'll have to use the rawQuery approach and pass either a DISTINCT or GROUP BY sql query.

Usage of rawQuery for this scenario has been answered here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download