Database Reference
In-Depth Information
Figure 6.53
Use IN with subquery that may return multiple values.
Highlight the code and click Run . he result of the query is shown in Figure 6.53.
5. Example 4: Select the students who have completed the course VB and got an A grade
by using a nested subquery. Enter the below query.
SELECT FirstName, LastName
FROM STUDENT
WHERE StudentID IN (SELECT StudentID
FROM STUDENT_CLASS
WHERE Grade = 'A' AND
ClassID IN (SELECT ClassID
FROM CLASS
WHERE CourseID = 'ISC2301'))
Highlight the code and click Run . he result of the query is shown in Figure 6.54.
6. Example 5: Select the irst name(s) and last name(s) of the student(s) advised by
Professor Garza by using the EXISTS operator. Enter the below query.
SELECT FirstName, LastName
FROM STUDENT S
WHERE EXISTS (SELECT *
FROM FACULTY F
WHERE S.FacultyID = F.FacultyID AND
F.LastName = 'Garza')
Highlight the code and click Run . he result of the query is shown in Figure 6.55.
Notice that, to relate the main query and subquery, you need to add the condition
S.FacultyID = F.FacultyID, where S is the alias for the STUDENT table and F is the
Search WWH ::




Custom Search