Anybody have any thoughts on how to get a list of distinct values out of a particular field in a database? There are 26,000 documents and the distinct value list is around 200 items.
I’d like to use only the API, but I’m not totally opposed to creating a view. I’m just not sure what the SELECT formula should look like to give me a list of documents with distinct values on the field in question.
Cheers.
Steve Maring
Subject: how do I select distinct column values from java
Steve -
This is a fairly crude example but if I understand your question correctly, it might be enough to help you out without having to create a new view.
The output should be something like this:
Non-unique unsorted value count: 6
Non-unique unsorted values:
[MNO, GHI, ABC, JKL, DEF, ABC]
Unique sorted value count: 5
Unique sorted values:
[ABC, DEF, GHI, JKL, MNO]
// here’s the code
import java.util.*;
class UniqueVector {
public UniqueVector() {
}
public static Vector getUniqueVector(Vector pvecTarget) {
HashSet ahsetUniqueVals = new HashSet(pvecTarget);
pvecTarget = new Vector(ahsetUniqueVals);
Collections.sort(pvecTarget); /* remove this line if you don't want it sorted */
return pvecTarget;
}
public static void main(String[] args) {
Vector avec = new Vector(6);
avec.add("MNO");
avec.add("GHI");
avec.add("ABC");
avec.add("JKL");
avec.add("DEF");
avec.add("ABC");
System.out.println("Non-unique unsorted value count: " + avec.size());
System.out.println("Non-unique unsorted values:\n\t" + avec);
avec = UniqueVector.getUniqueVector(avec);
System.out.println("Unique sorted value count: " + avec.size());
System.out.println("Unique sorted values:\n\t" + avec);
}
}