Codeigniter Join with Multiple Conditions
@Dodinas: I got the solution interms of MYSQL Query. I am finding it hard to convert the query into CI Active Record. But try this:
$sql = "SELECT `name`, CONCAT(`u1`.`first`,' ', `u1`.`last`) as a_1, CONCAT(`u2`.`first`,' ', `u2`.`last`) as a_2, CONCAT(`u3`.`first`,' ', `u3`.`last`) as a_3 FROM `clients` LEFT JOIN `users` as `u1` ON (`u1`.`id`=`a_1`) LEFT JOIN `users` as `u2` ON (`u2`.`id`=`a_2`) LEFT JOIN `users` as `u3` ON (`u3`.`id`=`a_3`)"; $result = $this->db->query($sql);
Try this
$this->db
->select('*')
->from('clients')
->join('users', 'users.id = clients.a_1 OR users.id=clients.a_2 OR users.id = clients.a_3');
$query = $this->db->get();
return $query->result();