Error "1052 Column in where clause is ambiguous"?

1

I'm having trouble making a system. I'm doing a join and the following error appears:

  

Error Number: 1052 Column 'donor_id' in where clause is ambiguous   SELECT * FROM doacao JOIN doador ON doacao . id_doador =   'donor . donor_id WHERE donor_id' = '1'

Below is my method in the model.

    public function minhasDoacoes(){
    $id_doador = $this->session->userdata('id_doador');
    $this->db
    ->select('*')
    ->from('doacao')
    ->join('doador', 'doacao.id_doador = doador.id_doador')
    ->where('id_doador', $id_doador);
    return $this->db->get()->result();
}
    
asked by anonymous 07.10.2016 / 01:34

1 answer

2

No where include the same table name ( doador.id_doador ) in this example:

public function minhasDoacoes(){
    $id_doador = $this->session->userdata('id_doador');
    $this->db
    ->select('*')
    ->from('doacao')
    ->join('doador', 'doacao.id_doador = doador.id_doador')
    ->where('doador.id_doador', $id_doador);
    return $this->db->get()->result();
}

The problem is that it does not know which id_doador is doing where because it has two fields with the same name. Nothing prevents doacao.id_doador from being placed in this case with the same result.

    
07.10.2016 / 01:41