Drop Table
Support Forum for database administrators and web based access to important newsgroups related to databasesHi, I have a Student table and course table. Every student will enroll in 3 courses. The strucutre of the table is Student ----------- Studentid, Student Name, Course1ID, Course2ID, Course3ID I have the course table Course ------------ CourseID, CourseName Can someone tell how to write a query to get the course Names for a particular student. Sampel output should be something like this. StudentName1, CourseName1, CourseName2, CourseName3. Thanks in advance Dilip
Post Follow-up to this messageIf a studen always has all 3 coursids then get rid of the left joins and the coalesce select s.StudentName, coalesce(c1.CourseName,'N/A') as CourseName1, coalesce(c2.CourseName,'N/A') as CourseName2, coalesce(c3.CourseName,'N/A') as CourseName3 from student s left join Course c1 on s.Course1ID = c1.CourseID left join Course c2 on s.Course2ID = c2.CourseID left join Course c3 on s.Course3ID = c3.CourseID http://sqlservercode.blogspot.com/
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread