Retrieving data from multiple tables
-
Hello! I am trying to retirve data from almost five tables simultaneously, but having problems in use of a single query!!! Here is the sample of thouse five tables students: stuid, classID, sectionID, termID, sessionID, stuName, other fields Classes: classID, className Sections: sectionID, sectionName Terms: termID, termName Sessions: sessionID, sessionName NOw if i want to extract data with a single query in somewhat this form stuName, className, sectionName, termName, sessionName Can someone help me in this, as to how the best query can be formed? thank you!! -- modified at 1:28 Monday 30th July, 2007
-
Hello! I am trying to retirve data from almost five tables simultaneously, but having problems in use of a single query!!! Here is the sample of thouse five tables students: stuid, classID, sectionID, termID, sessionID, stuName, other fields Classes: classID, className Sections: sectionID, sectionName Terms: termID, termName Sessions: sessionID, sessionName NOw if i want to extract data with a single query in somewhat this form stuName, className, sectionName, termName, sessionName Can someone help me in this, as to how the best query can be formed? thank you!! -- modified at 1:28 Monday 30th July, 2007
SELECT stuName = s.stuName, className = c.className, sectionName = sc.sectionName, termName = t.termName, sessionName = ss.sessionName FROM students s LEFT OUTER JOIN Classes c ON s.classID = c.classID LEFT OUTER JOIN Sections sc ON s.sectionID = sc.sectionID LEFT OUTER JOIN Terms t ON s.termID = t.termID LEFT OUTER JOIN Sessions ss ON s.sessionID = ss.sessionID Eliz.K
-
SELECT stuName = s.stuName, className = c.className, sectionName = sc.sectionName, termName = t.termName, sessionName = ss.sessionName FROM students s LEFT OUTER JOIN Classes c ON s.classID = c.classID LEFT OUTER JOIN Sections sc ON s.sectionID = sc.sectionID LEFT OUTER JOIN Terms t ON s.termID = t.termID LEFT OUTER JOIN Sessions ss ON s.sessionID = ss.sessionID Eliz.K
Thank You Eliz! One thing more, also if i want to get the record of a single student, can i used the where clause after joins like where s.stuid = '2222' ??? thanks!!!
-
Thank You Eliz! One thing more, also if i want to get the record of a single student, can i used the where clause after joins like where s.stuid = '2222' ??? thanks!!!
Yes you can :) Eliz.K www.oin1.com