1

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();

1 Answer 1

2

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';
Sign up to request clarification or add additional context in comments.

2 Comments

hey subquery is normal sql?
oops... sorry.. its oops.. sorry.. its $subQuery=$model->getCommandBuilder()->createFindCommand($model->getTableSchema(),$criteria)->getText();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.