Yii CActiveDataProvider UNION ALL

时间:2013-01-17 07:45:02

标签: php mysql yii

我想如何在UNION ALL CActiveDataProvider上使用criteria

表示例:

ID    NAME
1     John

查询示例:

SELECT * FROM users 
  UNION ALL 
SELECT * FROM users

响应:

ID    NAME
1     John
1     John

1 个答案:

答案 0 :(得分:3)

CDbCriteria无法处理UNION ALL

的sems

相反,您可以使用CSqlDataProvider

$sql='SELECT * FROM tbl_user UNION ALL SELECT * FROM tbl_user ';
$dataProvider=new CSqlDataProvider($sql, array(
    'totalItemCount'=>$count,
    'sort'=>array(
        'attributes'=>array(
             'id', 'username', 'email',
        ),
    ),
    'pagination'=>array(
        'pageSize'=>10,
    ),
));
// $dataProvider->getData() will return a list of arrays.