1
votes

Query is not filtering the duplicate rows from two tables in grocery crud, i'm trying to show one list without duplicates and it seems query is being ignored by the controller. what am i doing wrong?

Model

public function delete_duplicaterow() { 
    $query = $this->db->query('SELECT intervaloHorario, cita FROM intervaloshorarios JOIN citas '
                    . 'ON intervaloshorarios.idIntervaloHorario = citas.idIntervaloHorario '
                    . 'GROUP BY intervaloshorarios.intervaloHorario, citas.cita');
     return $query->result();
    }

Controller

$this->Fechacita_Model->delete_duplicaterow();

Database

Database

1

1 Answers

1
votes

I notice that you're grouping on intervaloshorarios.intervaloHorario and citas.cita. You probably need to rethink your JOIN clause to join on both intervaloshorarios.intervaloHorario and citas.cita so that there is a 1:1 join with no row duplication. Without seeing your table structure, I have to assume that you're generating duplicates because intervaloshorarios.idIntervaloHorario and citas.idIntervaloHorario has a 1-to-many relationship.