i need to get only one coincidence from the database, i use the ClistView widget to show multiple records, but i need it to not show duplications.
for now, this is my controller/action
public function actionIndex()
{
$criteria = new CDbCriteria(array(
'condition'=>'host=:id OR users_id=:id',
'params'=>array('id'=>Yii::app()->user->getId()),
));
$dataProvider=new CActiveDataProvider('sigstur', array(
'criteria'=>$criteria
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
there are records that have same values on host and user_id columns but with different data in other columns, with this condition im just asking to show records with theses params, but there are too many duplications, how to avoid theses duplications?
As I see it you have to solutions:
1) Use a GROUP BY
:
$criteria = new CDbCriteria(array(
'condition' => 'host=:id OR users_id=:id',
'params' => array('id'=>Yii::app()->user->getId()),
'group ' => 'host, users_id',
));
2) Use a DISTINCT
:
$criteria = new CDbCriteria(array(
'condition' => 'host=:id OR users_id=:id',
'params' => array('id'=>Yii::app()->user->getId()),
'distinct' => true,
));
If you explain what kind of duplication you want to avoid I could add more details in my answer.