Код: Выделить всё
select * from chat t3 inner join (select t1.* from chat_has_users t1 inner join chat_has_users t2 on t1.chat_id = t2.chat_id where t1.users_id = 39 and t2.users_id = 15) t4 on t4.chat_id = t3.id;
Код: Выделить всё
select * from chat t3 inner join (select t1.* from chat_has_users t1 inner join chat_has_users t2 on t1.chat_id = t2.chat_id where t1.users_id = 39 and t2.users_id = 15) t4 on t4.chat_id = t3.id;
Код: Выделить всё
$subQuery4 = ChatHasUsers::find()
->alias('t1')
->where(['t1.users_id' => 39])
->innerJoin(ChatHasUsers::tableName() . ' t2', 't2.users_id = :t2users AND t1.chat_id = t2.chat_id', ['t2users' => 15])
$query = Chat::find()
->alias('t3')
->innerJoin(['t4' => $subQuery4], 't4.chat_id = t3.id')
->all();