Error "1052 Column in Where clause is ambiguous"?

Asked

Viewed 756 times

1

I am having problems performing a system. I am doing a Join and the following error appears:

Error Number: 1052 Column 'id_doador' in Where clause is ambiguous SELECT * FROM doacao JOIN doador ON doacao.id_doador = 'donor.donorWHEREid_donor` = '1'

Below is my model method.

    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();
}
  • Hello all right? Wouldn’t it be ->where('doador.id_doador', $id_doador); ?

1 answer

2


In the where include the table name (doador.id_doador) equal 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 he doesn’t know which id_doador is doing the where for having two fields with the same name. Nothing prevents it from being placed doacao.id_doador in this case bringing the same result.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.