|
Comments on designing SQL Queries:
0. Start with the SELECT... FROM... WHERE... template.
|
Problem 6 on page 617 (Ch. 13) of [SG3].
|
Output of the Query:
|
Consider a database with 3 tables,
STUDENT-INFO,
COURSE-INFO, and
ENROLMENT.
Assume
•
the STUDENT-INFO table has 30,000 (3x104) rows,
•
the COURSE-INFO table has 1,000 (103) rows,
•
the ENROLMENT table has 100,000 (105) rows.
| Student-ID | Name | NRIC-ID | Address | Tel-No | Faculty | Major |
|
... |
... |
... |
... |
... |
... |
... |
|
|
SELECT Name, Faculty, Course-ID
FROM SI, EN
WHERE (Student-ID='U2908888P') and (SI.Student-ID = EN.Student-ID)
|
(b,c)(i) List the Student-ID, Name, Tel-No of the all "CS" majors;
SELECT SI.Student-ID, SI.Name, SI.Tel-No
FROM SI
WHERE (SI.Major="CS")
|
(b,c)(ii) List the Student-ID, Name, Tel-No of the students enrolled in course "UIT2201";
SELECT SI.Student-ID, SI.Name, SI.Tel-No
FROM SI, EN
WHERE (EN.Course-ID="UIT2201")
AND (SI.S-ID = EN.S-ID)
|
(b,c)(iii) List the Student-ID, Name, Tel-No of students taught by instructor "LeongHW".
SELECT SI.Student-ID, SI.Name, SI.Tel-No
FROM SI, CI, EN
WHERE (CI.Instructor="LeongHW")
AND (SI.S-ID = EN.S-ID)
AND (CI.C-ID = EN.C-ID)
|