user3089273
user3089273

Reputation: 126

creating query with subquery in yii

Hi All I have following query to be executed. I am executing it as a string sql but is there any way I can convert it into criteria format or proper command format in Yii...

$sql="select * from costing inner join 
                (select * from storage inner join costing_user_binding psb on user.user=psb.fk_user_id where user.fk_users_id IN $parents_id)
                view on costing.costing_id=view.fk_costing_id where costing.fk_user_types_id = {$session['role_level']} and costing.fk_product_types_id=2";
            $result = Yii::app()->db->createCommand($sql)->queryAll();

Upvotes: 1

Views: 1118

Answers (1)

Dirgh
Dirgh

Reputation: 507

You can try this...

$subQuery=$model->getCommandBuilder()->createFindCommand($model->getTableSchema(),$criteria)->getText();

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

Upvotes: 2

Related Questions