mercredi 5 décembre 2018

Duplicated rows that doesn't match on Laravel

I am doing a query in Laravel, in this query I have to join two tables to obtain information, the problem is that the only parameter where I can join them isn't unique. So when I print the results instead of getting something like

a - 1 b - 2 c - 3

I am getting

a - 1 a - 2 a - 3 b - 1 b - 2 b - 3

The query is the next one:

$hist = DB::table('codigo')
                ->join('llamada', 'codigo.idPaciente', '=', 'llamada.id_paciente')
                ->where('llamada.status_llamada', 'Finalizada')
                ->whereRaw('llamada.fecha_inicio > DATE_SUB(codigo.created_at, INTERVAL 6 HOUR)')
                ->whereRaw('llamada.fecha_inicio < DATE_ADD(codigo.created_at, INTERVAL 48 HOUR)')
                ->where(function($query){
                    $query->where('llamada.status_pago', '=', 'Sis')
                    ->orWhere('llamada.status_pago', '=', 'RedSis');
                })
                ->where(function($query){
                    $query->where('llamada.rec', '=', 1)
                    ->orWhereNotNull('llamada.ord')
                    ->orWhereNotNull('llamada.inter');
                })
                ->get();

The whereRaws clauses are for some rules that I need to get the correct result but I still get duplicates because sometimes multiple data enters in that range.

Any suggestions to improve this? Thanks!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2UhtieT
via IFTTT

Aucun commentaire:

Enregistrer un commentaire