Iam new to SQL and I have to create SQL statement to select from following tables:
studentTable (studentID, firstName, lastName)
enrollmentTable (studentID, courseID, semester, year, grade)
(studentID and courseID are foreign keys)
courseTable (courseID, semester, year, name)
prereqTable (courseID, prereqID)
I have to select students that enrolled course but don't have fulfilled all prereq.
EDIT:
After a while I got the right solution. The key was to use multiple selects and it worked like a charm.
SELECT * FROM studentTable
WHERE EXISTS(
SELECT * FROM enrollmentTable, prereqTable
WHERE enrollmentTable.studentID = studentTable.studentID
AND prereqTable.courseID = enrollmentTable.courseID
AND NOT EXISTS (SELECT * FROM enrollmentTable
WHERE enrollmentTable.courseID = prereqTable.prereqID
AND enrollmentTable.studentID = studentTable.studentId)
)
After a while I got the right solution. The key was to use multiple selects and it worked like a charm.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.