CodeIgniter两个表左连接不返回连接条件右表中未命中时的左表的id [英] CodeIgniter Two tables Left Join does not return Join Condition id of left table when miss in right table

查看:350
本文介绍了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。*');

这篇关于CodeIgniter两个表左连接不返回连接条件右表中未命中时的左表的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆