Answer the question
In order to leave comments, you need to log in
How to form a union query in ActiveRecord yii2?
here is the actual request
SELECT id, name_film, slug_film, created_at FROM `fl_film`)
UNION
(SELECT id, name_mfilm, slug_mfilm, created_at FROM `fl_mfilm`)
UNION
(SELECT id, name_serial, slug_serial, created_at FROM `fl_serial`)
ORDER BY `created_at` DESC
LIMIT 10
Answer the question
In order to leave comments, you need to log in
So?
$query1 = MyModel::find()
->select("id, category_id AS type, name")
->limit(10);
$query2 = MyModel::find()
->select('id, type, name')
->limit(10);
$query1->union($query2);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question