Union Query

Hi,

i have a table ‘annonce’ that contains several articles.

some of them are PREMIUM

In my CgridView,I’m tryng to display 3 Premium articles, and then the rest

I can’t get this working but it works fine if I do it in phpMyAdmin as so :




(SELECT * FROM annonce ORDER BY is_premium DESC, id DESC LIMIT 0,3)

UNION 

(SELECT * FROM annonce ORDER BY id DESC LIMIT 0,30)



can anyone help me with this ?

here’s a part of my Yii Code :




$criteria=new CDbCriteria(array(

        'condition'=>'t.is_deleted=0 AND t.is_valid=1',

			));


$criteria->order = 't.id DESC';


$criteria->together = TRUE;




$dataProvider=new CActiveDataProvider('Annonce', array(

     'pagination'=>array(

          'pageSize'=>10,

     ),

     'criteria'=>$criteria,

));



Thannks alot !

I would create a database view that acts as stated, and create an AR model for it.

(LIMIT on the second part may not be necessary.)

Please note that you can create an AR model for database view. You just have to supply the view name instead of the table name when you use the model creator of gii. :)