我一直在
不唯一的表/别名:'users'
运行我的Active Record查询...
$this->db->select('*');
$this->db->from('faults');
$this->db->join('users','users.user_id = faults.customer_id');
$this->db->join('users','users.user_id = faults.engineer_id', 'left outer');
$this->db->where('faults.fault_id', $fault_id);
其翻译为(在MySQL中):
SELECT * FROM (`faults`) JOIN `users` ON `users`.`user_id` = `faults`.`customer_id` LEFT OUTER JOIN `users` ON `users`.`user_id` = `faults`.`engineer_id` WHERE `faults`.`fault_id` = '1'
我看过this answer,但不知道如何将其转换为我的有效记录查询?
任何帮助表示感谢。
干杯
答案 0 :(得分:1)
您需要添加别名'...
$this->db->select('*');
$this->db->from('faults AS F0');
$this->db->join('users' AS U0, 'U0.user_id = F0.customer_id');
$this->db->join('users' AS U1, 'U1.user_id = F0.engineer_id', 'left outer');
$this->db->where('F0.fault_id', $fault_id);
答案 1 :(得分:0)
private $_fautls_table = 'fautls';
$this->db->from('fautls as f')
$this->db->join($this->_users_table . ' AS u', 'u.user_id = f.customer_id');
$this->db->join($this->_users_table . ' AS uu', 'uu.users_id = f.engineering_id');