当我加入两个表时,不返回空值。返回先前的数据

时间:2015-06-08 11:47:52

标签: php mysql sql join yii2

在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();

我加入表:

This is my joining table MyBase表:

This is my base table

我希望输出如下: This is my out table.. iwant the text null or blank space in the sprint name column of the clearanz2 iteration

请帮我解决这个问题

感谢。

1 个答案:

答案 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();