Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL for spreadsheet output
> How do I structure my sql statement so that I get this result?
You probably want more than one student in a course and more than one course for a student. so probably you want a many-many relationship between TblStudent and TblCourse. You might want:
TblCourse = { CourseId(PK), CourseName, CourseDate, Result } TblStudent = { StudentId(PK), StudentName, StudentSurname, StudentTel } TblStudentIsInCourse = { StudentId(FK), CourseId(FK) }
Given that, you can select
select * from TblCourse C, TblStudentIsInCourse SC
where C.CourseId = SC.CourseId
and SC.StudentId = :1
select * from TblStudent S, TblStudentIsInCourse SC
where S.StudentId = SC.StudentId
and SC.CourseId = :1
select * from TblStudent S, TblCourse C, TblStudentIsInCourse SC
where S.StudentId = SC.StudentId
and C.CourseId = SC.CourseID
Received on Fri Jul 23 2004 - 10:44:32 CDT
![]() |
![]() |