2

Now I have 2 tables

STUDENT:  

STUDENT_ID |  STUDENT_NAME | COURSE_ID  
1000       |  Anson        |     1  
1001       |  Jnson        |     1  
1002       |  Andy         |     2  
1003       |  Alex         |     3  

COURSE:

COUSE_ID  |  COURSE_NAME    
1         |   P5A  
2         |   P5B  
3         |   P5C

Now I would like to produce the result to show the students name in each class

Idea result:

P5A      P5B    P5C
Anson    Andy   Alex
Jason

what should I do, I am using php + mysql to build web system

1 Answer 1

2
select * from course c left join student s on c.course_id = s.course_id
order by c.course_name, c.course_id

Enumerate the result set. Each time course_id changes, start a new section.

Sign up to request clarification or add additional context in comments.

1 Comment

But when I print it out in PHP, how do I each row print P5A, P5B, P5C student corresponding?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.