I have 2 table
Table1
| id | name |
| ——– | ————– |
| 1 | Ulrich |
| 2 | Stern |
Table2
| id | school | tid|
| ——– | ————– | ——– |
| 1 | A | 1 |
| 2 | B | 1 |
I want to join 2 table to get all information. With SQL query like this
SELECT Table1.id, name, school FROM `Table1`
INNER JOIN `Table2`
ON Table1.id = Table2.tid
It gives me all information as I expect (I mean 2 rows with name ‘Ulrich’).
But when I do with Yii2 query
$query = self::find();
$query -> alias('t1')
-> innerJoin(['t2'=>'Table2'], 't1.id=t2.tid')
$result = NULL;
if($total = $query->count()) {
$result = $query
-> select([t1.*, t2.school])
->asArray()
->all()
;
$result[0]['count'] = $total;
}
it only gives me 1 row with name ‘Ulirch’.
Can anyone help me with this problem. Thank you very much.