CodeIgniter两个表左连接不返回连接条件右表中未命中时的左表的id
问题描述:
我有两个表说Table1和Table2和我左边连接Table1在Table2与Table1.PrimaryKey = Table2.ForeignKey。它返回两个表中的所有行,但在某些行中,由于表2中没有用于连接条件的记录,因此Table1缺少PrimaryKey字段值。这是我的代码
I have two tables say Table1 and Table2 and i am Left joining Table1 on Table2 with Table1.PrimaryKey = Table2.ForeignKey. It does return all the rows from both tables but in some rows, due to no record in Table2 for the join condition, the PrimaryKey field value is missing for Table1. Here is my code
$this->db->select('*');
$this->db->from('CI_Articles_Tbl');
$this->db->join('CI_Article_Images_Tbl',
'CI_Articles_Tbl.roflArticle_ID=CI_Article_Images_Tbl.roflArticle_ID','left');
$this->db->group_by('CI_Articles_Tbl.roflArticle_ID');
$query = $this->db->get();
return $query->result_array();
我的查询有什么问题,它的可能解决方案是什么。
What is the problem in my query and what is its possible solution. Any help will be highly appreciated.
答
您已选择表。 code>
You have select table.*
尝试此代码。
$ this-> db-> select('CI_Articles_Tbl。*');