在yii2中,我编写连接两个表的左连接查询。
如果基表只有一条记录,并且连接表有两条记录..
intProject_Id
是两个表的公共字段
如果一个值为一的记录为null,我需要它意味着它返回Null ..
现在,此处将显示以前的数据。
我的控制器代码:
$model2 = (new \yii\db\Query())
->select(['tbl_sprint.*','tbl_iteration.*'])
->from('tbl_sprint')
->leftJoin('tbl_iteration', 'tbl_iteration.intProject_Id = tbl_sprint.intProject_Id')
->where('tbl_iteration.intProject_Id = :intProject_Id', [':intProject_Id' => $projectid])
->all();
我加入表:
MyBase表:
我希望输出如下:
请帮我解决这个问题
感谢。
答案 0 :(得分:1)
请尝试以下查询。
$model2 = (new \yii\db\Query())
->select(['tbl_sprint.*','tbl_iteration.*'])
->from('tbl_sprint')
->innerJoin('tbl_iteration', 'tbl_iteration.intProject_Id = tbl_sprint.intProject_Id')
->where('tbl_iteration.intProject_Id = :intProject_Id', [':intProject_Id' => $projectid])
->all();