Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

SQL Server Query help
Hi,
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


Report this thread to moderator Post Follow-up to this message
Old Post
dilip.movva@gmail.com
11-30-05 06:23 PM


Re: SQL Server Query help
If 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/


Report this thread to moderator Post Follow-up to this message
Old Post
SQL
12-01-05 01:23 AM


Re: SQL Server Query help
Thank you very much.

- Dilip


Report this thread to moderator Post Follow-up to this message
Old Post
dilip.movva@gmail.com
12-01-05 01:23 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

MS SQL Server archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 11:17 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006