Answer the question
In order to leave comments, you need to log in
How to form a SQL query in Yii2?
Hello, help me to form a SQL query in Yii2.
There are 3 tables:
This SQL query works and outputs everything correctly, but I can’t figure out how to translate it into Yii2, after looking through the documentation I couldn’t display the second INNER JOIN (I output only one).
SELECT * FROM bd.group
INNER JOIN bd.account2group ON bd.group.id = bd.account2group.group_id
INNER JOIN bd.account ON bd.account2group.account_id = bd.account.id
WHERE bd.group.id = 8
$model = Group::find()
->innerJoin('account2group', 'id = account2group.group_id')
->innerJoin('account', 'account2group.account_id = account.id')
->where(['id' => 8])
->asArray()
->all();
return $model;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question