Giacomo P. Tue Sep 14 15:52:09 -0400 2010

Subject: Add "DISTINCT" to finder

Hi all,

I'm using PHP 5.3 + mySQL 5.1.31 and I'm looking for how to add a "DISTINCT" to a finder, I would get this query:
And I'm using this syntax:

$join = 'JOIN Options_per_Orders ON
(Options.`idoption` = Options_per_Orders.`idoption`) JOIN Orders ON
(Options_per_Orders.`idorder` ='.$order[$i]->idorder.' ) ORDER BY category ASC';

$option = Option::all(array('joins' => $join));

Thank you

Giacomo P. Tue Sep 14 15:59:20 -0400 2010

I found a trick using "GROUP BY" instead of "ORDER BY" but maybe someone need an answer to the question too :)

Jacques Fuentes Tue Sep 14 19:33:35 -0400 2010

You can do the following

$option = Option::all(array('select' => 'DISTINCT *', 'joins' => $join));

Read about it here

asava samuel Thu Mar 07 18:19:32 -0500 2013


Here is an ORM that works with MySQL

Richard Hendershot Wed Jun 19 09:38:56 -0400 2013

I think OP wanted a finder that could be added to the model subclass. I do. Thinking it's relevant....

I have to use an externally defined schema where a descriptive attribute is non-normalized. Call it Book.Category. Category is a string but no other constraint. I can use your example, but what I really need is to be able to define Book extends Model


such that I don't have to replicate that SQL throughout my code. I've looked at dynamic finders but they don't appear to support select criteria like distinct. TIA!