0

我有 3 张桌子,我想加入他们。如果这三个有一个领域彼此相似,那将很容易。问题是,table1 和 table2 有一个相似的字段,table2 和 table3 有另一个相似的字段,但是根本没有相似的字段可以连接 table1 和 table3。我尝试使用下面的代码加入他们,但它不起作用。我收到一个错误,字段“branch_name”未定义:

    $this->db->select('r.*,                          
                       b.id as branch_id,                           
                       b.name as branch_name');
    $this->db->join('users_branches AS ub', 'ub.user_id = r.user_id');
    $this->db->join('branches AS b', 'b.id = ub.branch_id');

    $this->db->where('payroll_period_id',$payroll_period_id);        
    return $this->db->get('dtr r');

有什么解决办法吗?

4

1 回答 1

0

尝试放入$this->output->enable_profiler(TRUE)您的控制器以查看已执行的 SQL。这样更容易排除故障。我通常会复制执行的 SQL 并在 MySQL 客户端中对其进行故障排除,看看出了什么问题。

于 2013-08-01T06:26:08.047 回答