0

I'm trying to do this join in laravel query builder but it is throwing and error. I'm using and Mysql DB. This is my sql:

select c.*, d.* from notas_cabecera c
join notas_detalle d on (c.codigo_nota = d.codigo_nota)
where c.codigo_nota in (select r.codigo_nota from reportes r); 

And this is my laravel query:

$lista_reportes = DB::table('notas_cabecera')
                              ->join('notas_detalle', 'notas_cabecera.codigo_nota', '=', 'notas_detalle.codigo_nota')
                              ->whereIn('notas_cabecera.codigo_nota', function($query)
                              {
                                    $query->select(
                                              DB::table('reportes')->select('reportes.codigo_nota')
                                            );
                              })
                              ->get();

What I'm doing wrong? please help.

1
  • 1
    For starters, you're not telling us what the error is. Commented Jan 31, 2015 at 2:17

1 Answer 1

1
$lista_reportes = DB::table('notas_cabecera')
                              ->join('notas_detalle', 'notas_cabecera.codigo_nota', '=', 'notas_detalle.codigo_nota')
                              ->whereIn('notas_cabecera.codigo_nota', function($query)
                              {
                                    $query
                                        ->select('reportes.codigo_nota')
                                        ->from('reportes');
                              })
                              ->get();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.