Query mysql with special condition

Asked

Viewed 27 times

0

I’m having trouble assembling a query with two tables.

In my comic I have two tables called disciplines and bulletin, in disciplines have the data of each discipline and in bulletin have the foreign keys referencing the student and the discipline and a field with the student’s grade for that discipline.

I want to assemble a query with the junction of the two tables that returns all the disciplines and also the grades for each one, but even if there is no record in the bulletin table for the discipline.

I tried to do as below, but this way only shows the disciplines that have a record in the table bulletin, and I want even if you do not have the record appear the disciplines with the attribute empty note.

SELECT d.id, d.nome, d.periodo, d.curso, d.ordem, b.nota d FROM disciplinas d LEFT JOIN boletim b ON (d.id = b.disciplina) WHERE (d.curso = :curso AND b.aluno = :aluno) ORDER BY d.ordem, d.id ASC

Can someone help me with that?

  • in b.disciplina, that column saves what ? A string or int ?

  • @Leandrolima is a foreign key referencing the discipline (INT)

No answers

Browser other questions tagged

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