Mysql > query with dynamic columns

Asked

Viewed 149 times

0

Friends I have a question.... I have the following tables in Mysql:

alunos (id, nome, etc)
turmas (id, turma, etc)
matricula (id, turmaID, alunoID)
disciplinas (id, turmaID)
avaliacoes (id, avaliacao)
notas (id, matriculaID, disciplinaID, avaliacaoID, nota)

I can perform the query using JOIN satisfactorily and returning the information correctly. Evaluations will be the same for each discipline, however the number of evaluations is variable. Thus, students' grades are returned line by line. It would be possible to join in a Query the grades of the student’s evaluations in the same line?

EX: 
disciplina   aluno          Nota1   Nota2   Nota3
Matemática | joao manoel  | 10    | 8     | 9

I hope I have been able to express myself... I thank you for your help!

  • One of the most practical ways is to use Joins, one searched on the site by JOIN and MYSQL can help. I imagine it has been answered already, if I find link put here.

  • Here is an example very similar to what you need: http://answall.com/questions/114581/70

  • Here is some legal material to understand Joins: http://answall.com/questions/6441/70

  • As for the formatting of the result, to avoid showing repeated columns (which is inevitable in a Join of this type), we have some posts as well, but it depends on specifying which language is used for display

  • Dear @Bacco, thank you so much for the speed with which you answer. I can do the JOINS satisfactorily between the tables and return the values correctly. However, my doubt would be as to how to display the same result. I thought there could be another way to return the records more "chewed" for HTML.

  • If you are using HTML, you are probably using a connection layer between Mysql and HTML. This is the case of formatting in this layer, whether PHP or qq other language. I’ve already answered a couple of questions on the website about how to avoid repeating titles, and the logic is very simple.

  • Now, important in your case, when so, explain everything in the question, because some colleague could have lost the longest time to help you posting JOIN, and the problem is another. It is the suggestion of [Dit] and describe the problem in a more complete way, making clear the difficulty (what tried, which code already has, and what came out different than expected), then we can indicate an answer with the best solution, or if there is, answer exactly upon the doubt.

  • Okay. You can let me take your advice! Thank you!

Show 3 more comments
No answers

Browser other questions tagged

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