This post is the answer to Mandy Singh’s comment to the article Select distinct with CakePHP in which he asked how to use “count” with “distinct”. The answer I gave then — to use a custom query — works, but there exists a more Cake-like solution.
The obvious solution — using findCount() — doesn’t work, as there is no way to specify that you want to use “distinct”.
So to get the desired result we have to use a find() or findAll() statement as shown in the following example:
$this->User->find(null, "COUNT(DISTINCT User.city) AS 'count'");

Hey Thanks :) Yes, this is how I finally did it too :) I am sure others will find it very handy and useful.
CakePHP DISTINCT の使用方法…
cakebaker » Using distinct and count with CakePHP
CakePHP で DISTINCT を使いたい時の方法が紹介されていました。
$this->User->find(null, “COUNT(DISTINCT User.city) AS ‘count’”);
find は /cake/libs/model/model_php5.php で…
[...] From cakebaker.42dh.com [...]