For combine the result of two or more select query we use union in sql query.If you want to use union in yii query you can use the below code
$queryFirst = (new \yii\db\Query())
->select("id, name")
->from('tableA')
->limit(10);
$querySecond = (new \yii\db\Query())
->select('id, name')
->from('tableB')
->limit(10);
$queryFirst->union($querySecond);
this will be equivalent to
SELECT id,name FROM tableA
UNION
SELECT id,name FROM tableB;
0 Comment(s)