I’m new to Laravel, I wanted to make a union with the DB and it didn’t work for me, I tried it in SQL and it worked fine, I don’t know what I’m doing wrong?
Would you be kind enough to help me with this dilemma, thanks
here is the SQL query:
SELECT SUM(materias.Credito) FROM historico_notas INNER JOIN materias ON materias.id = historico_notas.materias_id INNER JOIN estudiante_seccion on estudiante_seccion.id = historico_notas.estudiante_seccion_id WHERE historico_notas.nota >= 10 and estudiante_seccion.id_persona = 627;
This is the generated query SQL:
here in my attempt in laravel:
$prueba = DB::table('historico_notas')
->join('materias','materias.id', '=',' historico_notas.materias_id ' )
->join('estudiante_seccion',' estudiante_seccion.id','=','historico_notas.estudiante_seccion_id' )
->where('historico_notas.nota','>=',10 )
->where(' estudiante_seccion.id_persona','=',$persona_alumno)
->sum('materias.Credito');
This is the generated query and error.
My dilemma is that I want my sql query to Laravel and something gives me an error and I don’t know what error I have
the SQL query works perfectly for me, but when I try to go to Laravel it gives me an error,
what i show is my attempt to pass the sql query to laravel and what i want is my sql query to laravel
How would the syntax be properly?
2
Answers
The error gets an unknown column "historico_notas.nota", you can check it in the table if it exists
I just converted your SQL into this.