Any way to do DISTINCT ON?
You could try with the distinct() method for dynamic queries and see how it goes with your query.

There is an example to follow on the taxonomy module of the Drupal core, on the following line:

$node_types = db_select($revision_name)
-&gt;distinct()
-&gt;fields($revision_name, array('bundle'))
-&gt;execute()
-&gt;fetchCol();