I understand that you can specify ->distinct() on the db_select statement so that it only returns distinct values when looking at ALL fields. But what I want is to return distinct values by only looking at ONE field. Here's my code:
$event_table = db_select('my_table', 'e')
->distinct()
->orderBy('e.time', 'ASC');//ORDER BY
$event_table->join('node', 'n', 'e.nid = n.nid'); //JOIN node with events
$event_table->groupBy('e.time');//GROUP BY time
$event_table->fields('e')//SELECT the fields from events
->fields('n',array('type','status','title'))//SELECT the fields from node
->orderBy('e.time', 'ASC');//ORDER BY
$result_event_table = $event_table->execute();
$result_event_table = $result_event_table->fetchAllAssoc('time');
Suppose I want the distinct column to be e.nid. You'd think ->distinct('e.nid') would work but it still returns distinct values based on all fields (i.e. distinct(columns1, column2, column3, etc).
db_select
into doing the same