php - 当codeigniter中Left Join表为空时查询返回空

标签 php mysql codeigniter

我正在使用 Codeigniter 和 MySql 7.5。我有一个查询,当左连接表为空时,它总是返回空。

$this->db->select('shop.id as shop_id, shop.shop_name, rg.rating');
$this->db->from('shop');            
$this->db->join('booking as bh', 'bh.shop_id = shop.id', 'left');
$this->db->join('rating rg', 'rg.booking_id = bh.id', 'left');
$this->db->group_by("bh.id");
$this->db->order_by("bh.id", "desc");

这里我在预订表和商店表中有条目,但评级表是空的。但我没有得到任何结果。

如果我从选择中删除rg. rating,它将返回正确的结果。

我错过了什么吗?谢谢

最佳答案

试试这个-

$this->db->select('shop.id as shop_id, shop.shop_name, rating.rating');
$this->db->join('booking', 'booking.shop_id = shop.id', 'left');
$this->db->join('rating', 'rating.booking_id = booking.id', 'left');
$this->db->group_by("booking.id");
$this->db->order_by("booking.id", "desc");
return $this->db->get('shop');

关于php - 当codeigniter中Left Join表为空时查询返回空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38719748/

相关文章:

php - 我可以使用其中一个场景作为我的元步骤而不是在 Context 类中定义它吗?

PHP mySQL 网站搜索脚本

php - 从字符串中的 ids 中检索表中的随机行

php - codeigniter 中的搜索框给出空白数据

php - 提交后显示提醒消息

php - 如何选择从mysql以php形式获取的值来更新数据

PHP 5.4 : Getting Fully-qualified class name of an instance variable

javascript - 在特定时间从数据库播放音频

mysql - 每行字段中某个值出现的次数

codeigniter - 销毁 Code Igniter 中的特定 session