php - CodeIgniter 两个表Left Join在右表缺失时不返回左表的Join Condition id

标签 php mysql codeigniter

我有两个表,即 Table1 和 Table2,并且我使用 Table1.PrimaryKey = Table2.ForeignKey 在 Table2 上左连接 Table1。它确实返回两​​个表中的所有行,但在某些行中,由于表 2 中没有用于连接条件的记录,因此表 1 中缺少 PrimaryKey 字段值。这是我的代码

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

我的查询中存在什么问题以及可能的解决方案是什么。 任何帮助将不胜感激。

最佳答案

您已选择table.*

试试这个代码。

$this->db->select('CI_Articles_Tbl.*');

关于php - CodeIgniter 两个表Left Join在右表缺失时不返回左表的Join Condition id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20418791/

相关文章:

python - 如何在Django orm中执行子查询?

php - mySQL 对多行求和并排名处理关系

php - 从 session ID 开始在数据库中查找值

javascript - 如何在 .js 文件的 javascript 函数中获取 php session 数据

java - 从网站地址列表中提取顶级域名

mysql - 使用外键创建表 - 错误 150

PHP:2 个开关不能很好地相互交互

php - CodeIgniter 4 - 如何在 View 中显示 Flashdata?

php - 在 Wordpress 的循环中显示每个帖子的类别名称

php - 更新查询不起作用并将字段更改为 0