Select distinct value

Hi,

I am trying to select distinct value from a table.




$models=Product::model()->findAll(array(

    'select'=>'t.Category',

    'distinct'=>true,

));



Using the above, I get an array of Active Record. What I want is an array of distinct product category. I am aware that I need to do a loop through and build array myself.

Is there a way to just get an array of distinct product category ?

Thank you




$models=Product::model()->findAll(array(

    'select'=>'t.Category',

    'group'=>'t.Category',

    'distinct'=>true,

));



I am afraid it is not working. I still get an array of ActiveRecord. Each AR has




     [CActiveRecord:_attributes] => array

        (

            'type' => array

            (

                '0' => ''

            )

        )



Could you post your Product model ?

You’ll always get an array of Products from that query. What might make more sense would be to use CDbCommand to get the results you want and encapsulate that in a static method in the Product object. The above query should give you one product per category though.

Good topic. Thanks all

Thanks…

I am new one for YII and too much helpful.