I have:
$query1 = (new \yii\db\Query())
->select("id, category_id AS type, name")
->from('post')
$query2 = (new \yii\db\Query())
->select('id, type, name')
->from('user')
->orderBy('type');
$query1->union($query2);
This code generates the following SQL:
(SELECT `user`.`id`, `user`.`category_id` AS `type`, `user`.`name` FROM `post`)
UNION
(SELECT `user`.`id`, `user`.`category_id`, `user`.`name` FROM `post` ORDER BY `type`)
The SQL above does not order correctly.
It's necessary remove the parentheses. Ex:
SELECT `user`.`id`, `user`.`category_id` AS `type`, `user`.`name` FROM `post`
UNION
SELECT `user`.`id`, `user`.`category_id`, `user`.`name` FROM `post` ORDER BY `type`
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too