S
S
sawa42016-07-22 22:30:27
MySQL
sawa4, 2016-07-22 22:30:27

How to do Join with multiple conditions in yii2?

0b38d9a968964cacb407fb92b29e9d26.pngEverything is precious time.
Help me figure out
there is a table tbl1 (id, name), a second table tbl2 (id, id_tbl, name_tbl, name)
how to make a query correctly if the second table has no connection with the first, that is, the second table has an id of the first that can be repeated, and more the name of the first table, but the id can be the same since there can be a 3rd table.
Please show with an example. I already looked through Google, I didn’t see
in the picture, I hope it’s clear what I want

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Никита, 2016-07-22
@bitver

У вас же есть name_tbl, по нему и ориентируйтесь.
А вообще лучше 2 таблицы как tbl2 и не париться, а общее выбирать через union.

Максим Тимофеев, 2016-07-23
@webinar Куратор тега Yii

Вы не описали какой конкретно запрос Вы не можете составить. Поэтому вот пример наугад:
В модели к таблице 1:

public function getMydata(){
return $this->hasMany(SecondModel::classname(),['id_tbl'=>'id'])->andWhere(['name_tbl'=>'tbl1'])
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question