Yii2 merge queries like cdbcriteria in yii1
mysql, yii2
Solution
There is no `CDbCriteria` concept in `Yii2` anymore. Instead you can refer to the following classes:
- http://www.yiiframework.com/doc-2.0/yii-db-query.html (yii\db\Query)
- http://www.yiiframework.com/doc-2.0/yii-db-activequery.html (yii\db\ActiveQuery)
All you did before with `CDbCriteria` now you can do with above classes. So, there will be no need to merge two criteria with each other.
update
`Yii2` also supports sub-queries like below (as `Yii2`'s official guide):
$subQuery = (new Query)->select('COUNT(*)')->from('user');
$query = (new Query)->select(['id', 'count' => $subQuery])->from('post');
Which results in:
SELECT `id`, (SELECT COUNT(*) FROM `user`) AS `count` FROM `post`
http://www.yiiframework.com/doc-2.0/guide-db-query-builder.html#building-query
Problem
I have a problem regarding merge of multiple queries. In Yii 1.x you could merge a CDbCriteria with ``` $criteria->merge($otherCriteria) ``` How can I achieve the same nested conditions etc with queries in Yii2? Edit: Let's say I want separate queries to form subqueries. And after all subqueries are done I want to merge them together to the one big query.