Search code examples
mysqlcodeigniteractiverecordcodeigniter-2codeigniter-3

How to use where and join in codeigniter


I want to join 2 table 'enduser' and 'group'

$this->db->select('*');
$this->db->from('enduser');
$this->db->where('groupid', $id);
$this->db->join('group', 'group.groupid = enduser.groupid');
$query = $this->db->get();

I used this code but it is gives me an error :

Column 'groupid' in where clause is ambiguous

Please help.


Solution

  • The reason for the error message is: it cannot identify the table pointed in where condition.

    Change groupid in

    $this->db->where('groupid', $id);

    to

    $this->db->where('enduser.groupid', $id);

    or

    $this->db->where('group.groupid', $id);