Daily Archives: December 19, 2010


How to select distinct with Doctrine_Query 1

There is a bug with doctrine and many tickets have been opened for it from what I saw. Doing the following in a query will return no result

$q = Doctrine_Query::create()
	->select('distinct(datetime_scraped)')
	->from('Rate')
	->orderBy('datetime_scraped desc');

The solution is to alias the distinct column like below

$q = Doctrine_Query::create()
	->select('distinct(datetime_scraped) as datetime_scraped')
	->from('Rate')
	->orderBy('datetime_scraped desc');