Wednesday, March 7, 2012

hard query

hello

i have a proplem in query

i have 2 tables in my sql db one named stuednt include fields(id,name)

and one table named stu_cources include fields(id,course_name)

ok

i want to query the student that have courses EX. mcse

the result that i want from 2 tables

ID | NAME | Coures_NAME

in MSHFLEXGRID1

any one help me plz ...

I am assuming that the ID column in Student is an Identity and that the ID in Stu_Courses is a ForeignKey that relates back to the Student in the Students table.

Select S.ID, S.Name, SC.Course_Name
FROM Student S
INNER JOIN Stu_Courses SC ON S.ID = SC.ID
WHERE SC.Course_Name = 'MCSE'

|||

hi,

i don't know is the id in your courses table is the cource id or a student id?

i guess student table is basic table , and courses table is basic table if you gonna try to connect them you will have to type a cource per student i guess you have to add third table to get records from both basic tables to use as data entery (reocrdID,StudentID,CourceID)

in general to select related data from different tables you can use (from table1 inner Join table2 on table1.id = table2.relatedidfield)

best regards

|||just reference the corresponding tuple table.field in the select statement

No comments:

Post a Comment