Hi,
I have 2 tables as follows:
table1 (studid,studfir st,studlast)
table2 (resid,studid,r esnum,resgrade)
In table 1 are 2 records:
Record 1: '1','Michael',' Jackson'
Record 2: '2','John','Wil liams'
In table 2 are 8 records:
1,1,1,A-
2,1,2,B+
3,1,3,C-
4,1,4,A
5,2,1,C
6,2,2,C
7,2,3,B-
8,2,4,B+
My sql is
SELECT table1.studfirs t, table1.studlast , table2.resnum, table2.resgrade
FROM table1
JOIN table2 ON table1.studid = table2.studid
ORDER BY table1.studlast , table2.resnum
The output is currently
[HTML]<table>
<tr><td>Michael </td><td>Jackson</td><td>1</td><td>A-</td></tr>
<tr><td>Michael </td><td>Jackson</td><td>2</td><td>B+</td></tr>
<tr><td>Michael </td><td>Jackson</td><td>3</td><td>C-</td></tr>
<tr><td>Michael </td><td>Jackson</td><td>4</td><td>A-</td></tr>
<tr><td<John</td><td>Williams </td><td>1</td><td>C</td></tr>
<tr><td<John</td><td>Williams </td><td>2</td><td>C</td></tr>
<tr><td<John</td><td>Williams </td><td>3</td><td>B-</td></tr>
<tr><td<John</td><td>Williams </td><td>4</td><td>B+</td></tr>
</table>
[/HTML]
How can I change my sql statement to display the results as follows (with each student's information shown in only 1 row), using only 1 query:
[HTML]<table>
<tr><th>First </th><th>Last</th><th>Res1</th><th>Res2</th><th>Res3</th><th>Res4</th></tr>
<tr><td>Michael </td><td>Jackson</td><td>A-</td><td>B+</td><td>C-</td><td>A-</td></tr>
<tr><td>John</td><td>Williams </td><td>C</td><td>C</td><td>B-</td><td>B+</td></tr>
</table>[/HTML]
I can do it by looping through a query for each student but I would like it all done in 1 statement. Surely this is fairly easy for mysql?
I have 2 tables as follows:
table1 (studid,studfir st,studlast)
table2 (resid,studid,r esnum,resgrade)
In table 1 are 2 records:
Record 1: '1','Michael',' Jackson'
Record 2: '2','John','Wil liams'
In table 2 are 8 records:
1,1,1,A-
2,1,2,B+
3,1,3,C-
4,1,4,A
5,2,1,C
6,2,2,C
7,2,3,B-
8,2,4,B+
My sql is
SELECT table1.studfirs t, table1.studlast , table2.resnum, table2.resgrade
FROM table1
JOIN table2 ON table1.studid = table2.studid
ORDER BY table1.studlast , table2.resnum
The output is currently
[HTML]<table>
<tr><td>Michael </td><td>Jackson</td><td>1</td><td>A-</td></tr>
<tr><td>Michael </td><td>Jackson</td><td>2</td><td>B+</td></tr>
<tr><td>Michael </td><td>Jackson</td><td>3</td><td>C-</td></tr>
<tr><td>Michael </td><td>Jackson</td><td>4</td><td>A-</td></tr>
<tr><td<John</td><td>Williams </td><td>1</td><td>C</td></tr>
<tr><td<John</td><td>Williams </td><td>2</td><td>C</td></tr>
<tr><td<John</td><td>Williams </td><td>3</td><td>B-</td></tr>
<tr><td<John</td><td>Williams </td><td>4</td><td>B+</td></tr>
</table>
[/HTML]
How can I change my sql statement to display the results as follows (with each student's information shown in only 1 row), using only 1 query:
[HTML]<table>
<tr><th>First </th><th>Last</th><th>Res1</th><th>Res2</th><th>Res3</th><th>Res4</th></tr>
<tr><td>Michael </td><td>Jackson</td><td>A-</td><td>B+</td><td>C-</td><td>A-</td></tr>
<tr><td>John</td><td>Williams </td><td>C</td><td>C</td><td>B-</td><td>B+</td></tr>
</table>[/HTML]
I can do it by looping through a query for each student but I would like it all done in 1 statement. Surely this is fairly easy for mysql?
Comment