gpt4 book ai didi

mysql - 代码 Igniter JOIN 中的问题

转载 作者:行者123 更新时间:2023-11-29 13:24:25 24 4
gpt4 key购买 nike

我在 CI 事件记录表单中有此查询

$this->db->select('companies.*,comp_permissions.user_id');
$this->db->from('companies');
$this->db->join('comp_permissions', 'companies.id = comp_permissions.comp_id');
$query = $this->db->get();

它生成这样的查询

SELECT `hs_companies`.*, `hs_comp_permissions`.`user_id`
FROM (`hs_companies`)
INNER JOIN `hs_comp_permissions` ON `hs_companies`.`id` = `hs_comp_permissions`.`comp_id`

但是我原来的查询是

Select cb.*,cbp.user_id
from hs_companies cb
INNER JOIN hs_comp_permissions cbp ON
(cb.id = cbp.comp_id AND cbp.status=2 AND cbp.user_id = 72)

那么现在我如何在 JOIN 函数中放置多个列?

更新

当我这样尝试时

$this->db->select('companies.*,comp_permissions.user_id');
$this->db->from('companies');
$this->db->join('comp_permissions', '(companieas.id = comp_permissions.comp_id AND comp_permissions.status = 2 AND comp_permissions.user_id = 72)','inner');
$this->db->get()->result();

它生成以下结果

SELECT `hs_companies`.*, `hs_comp_permissions`.`user_id` 
FROM (`hs_companies`)
INNER JOIN `hs_comp_permissions` ON
(`hs_companies`.`id` = `hs_comp_permissions`.`comp_id` AND comp_permissions.status = 2 AND comp_permissions.user_id = 72)

它没有添加hs_我的数据库前缀

最佳答案

你能在WHERE caluses中设置它吗?

$this->db->select('companies.*,comp_permissions.user_id');
$this->db->from('companies');
$this->db->join('comp_permissions', 'companies.id = comp_permissions.comp_id');
$this->db->where('comp_permissions.status', '2');
$this->db->where('comp_permissions.user_id', '72');
$query = $this->db->get();

或者您可以手动设置数据库前缀:

$this->db->join('comp_permissions', '(companies.id = comp_permissions.comp_id 
AND hs_comp_permissions.status=2
AND hs_comp_permissions.user_id = 72)');

关于mysql - 代码 Igniter JOIN 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20347898/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com