0

I've got few tables in mysql.

table1 = students:
Id,
Name,
sName

table 2 = subjects:
Name

and for every name in subjects there is a table witch id and grade

Is there a way to make a query in MySql witch would print me something like that ? How can i do it ?

Name,sName,subjectName1,subjectName2...
John Miller A,A,B ...

I am sorry I am new here but it seems that someone added code to my question for me.

Also I am not sure how can i explain my question better.

I want to make a visual table that shows students and their grades and I am trying to do it as simple as possible.

I am trying to do that with JOIN but i am stuck at trying to use subject name in query not sure how to do that.


The subjects table is only to create columns in output table

Name | SecondName | Physics | Math | ...
John | Miller     |    A    |  B   |

Thats what i want

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Gumek
  • 3
  • 2
  • 1
    Welcome to SO. If you want to get some help here you should first of all show what you have already tried. – Bonifacio2 Dec 11 '14 at 14:40
  • After the edit also, I can't understand the question clearly – Gunaseelan Dec 11 '14 at 14:40
  • No 'id' in the subjects table, just 'Name'? And what are the fields in the third table you mention? (best show all three as SHOW CREATE TABLE output) – Hartmut Holzgraefe Dec 11 '14 at 14:45
  • I believe that you need something similar to this answer, take a look and see if it helps: http://stackoverflow.com/a/9668036/89435 – mavroprovato Dec 11 '14 at 14:52
  • It does sound to me like what you're looking for is a `PIVOT`. That is possible to do, but it's complicated because it's not exactly proper relational algebra especially without an aggregate function. As far as the database is concerned it's a display issue, and therefore not the database's problem. Usually it's recommended to do that sort of thing in the application instead of the database. – Bacon Bits Dec 20 '14 at 15:23

0 Answers0