the first
course,,,,,,,,,,,,have course_id(PK) ,course_name ....
the second
class,,,,,,,,,,,,,have class_id(PK) , course_id(FK) , class# ....
the third
class time,,,,,,have time_id(PK) , class_id(FK) , start , end , day ....
i want to select in one statement all of the :
course_name , class# , start , end , day
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted May 24, 2012, 11:30 PM
After SQL server 2000 the best practices is use inner join or outer join.
SELECT cu.course_name,cs.class#,ct.start,ct.end,ct.day
FROM course cu
INNER JOIN class cs ON cs.course_id=cu.course_id
INNER JOIN classtime ct ON ct.class_id=cs.class_id
Also Depending on Relation of these table use can use Right Outer or Left outer.
hope this will help u.
SenthilkumarPosted May 25, 2012, 12:02 AM
There are three tables in your list.
You need to use the join to combine the three table results.
Here in the first table, you have the course_id which also exists in the second table.
table1.course_id = table2.course_id
table2.class_id = table3.class_id
Use the inner join to combine the result set.
V S N Raju KanumuriPosted May 24, 2012, 10:52 PM
try this join query
select cu.course_name,cs.class#,ct.start,ct.end,ct.day from course cu,class cs,classtime ct where ct.class_id=cs.class_id and cs.course_id=cu.course_id