S
S
Sergey Beloventsev2016-07-20 11:34:09
Yii
Sergey Beloventsev, 2016-07-20 11:34:09

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

how to form a request.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2016-07-20
@Sergalas

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 question

Ask a Question

731 491 924 answers to any question