Using sub query for doubletts

You are viewing revision #1 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.

next (#2) »

at first find doubletts by db fields:

$model=new MyModel('search');
$criteria=new CDbCriteria();
$criteria->group = 'col1,col2,col3';
$criteria->having = 'COUNT(col1) > 1 AND COUNT(col2) > 1 AND COUNT(col3) > 1';

get the subquery:


add the subquery condition:

$mainCriteria=new CDbCriteria();
$mainCriteria->condition=' (col1,col2,col3) in ('.$subQuery.') ';
$mainCriteria->order = 'col1,col2,col3';

how to use:

$result = MyModel::model()->findAll($mainCriteria);

$dataProvider = new CActiveDataProvider('MyModel', array(
2 0
Viewed: 16 616 times
Version: Unknown (update)
Category: Tips
Written by: mb
Last updated by: mb
Created on: Aug 7, 2012
Last updated: 5 years ago
Update Article


View all history

Related Articles