mysql - 我们如何在事件记录中进行多重连接 Codeigniter

标签 mysql codeigniter activerecord

大家好,作为数据库和 Codeigniter 的初学者,您能帮帮我吗? 我们如何在事件记录中编写这个多内连接和左连接查询。

SELECT suppliers.*, category.strCategory, category_1.strCategory AS strParent, 
tblcitylist.city_name
FROM ((suppliers INNER JOIN category ON suppliers.intCat=Category.intId) INNER JOIN tblcitylist ON 
suppliers.intCity=tblcitylist.city_id) LEFT JOIN category AS category_1 ON 
category.intParent=Category_1.intId
WHERE status='y';

我有三个表 suppliers、tblcitylist 和 category。想要获取具有 intCat 和 intCity 的供应商的数据,结果是具有城市名称(city_name)和类别名称(strCategory)的供应商表的数据。 谢谢

最佳答案

也许这就是你想要的......

$query = $this->db->select('suppliers.*, category.strCategory, category_1.strCategory AS strParent, tblcitylist.city_name')
            ->from('suppliers')
            ->join('category',                  'suppliers.intCat=Category.intId',          'inner')
            ->join('tblcitylist',               'suppliers.intCity=tblcitylist.city_id',    'inner')
            ->join('category as `category_1',   'category.intParent=Category_1.intId',      'left')
            ->where('status','y')
                ->get();

CI 数据库文档:https://www.codeigniter.com/user_guide/database/index.html

关于mysql - 我们如何在事件记录中进行多重连接 Codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14517379/

相关文章:

ruby-on-rails - 按 belongs_to 自定义 foreign_key 搜索

mysql - Yii CDbCriteria 根据另一个表的计数选择行

mysql self 加入group_concat并且没有重复

php - 未获取产品广告 API AWS 的促销摘要

php - 在 PHP 中搜索和统计数据

ruby-on-rails - 在子模型中访问父对象

ruby-on-rails - 清理 SQL 语句中的存储过程调用

PHP - 使用 postman 更新查询返回成功但不更新数据库中的值

android - 与从大型数据库中选择所有行以填充 ListView 相关的性能问题

php - 如何在没有 Flash 支持的情况下使用 Ajax 和 Codeigniter 上传文件?