Reputation: 41
SELECT stu.First_Name, stu.Last_Name, stu.Phone
FROM Student stu
JOIN Enrollment e
ON stu.Student_Id = e.Student_Id
JOIN Section sec
ON e.Section_Id = sec.Section_Id
JOIN Course c
ON sec.Course_No = c.Course_No
WHERE c.Description = 'Systems Analysis' AND c.Description = 'Project Managment'
Hey all, hopefully the last question for today (I'm so sorry). I was wondering if there is a way to check for multiple string conditions (being an AND, not OR). When I use just one my joins work alright, but I can't seem to work past using both. My textbook wants me to solve it with only using the string keywords for the courses.
Upvotes: 0
Views: 63
Reputation: 263723
Use OR
and filter only the rows having the same number of instances to the the number of filter specified in the WHERE
clause.
SELECT stu.First_Name,
stu.Last_Name,
stu.Phone
FROM Student stu
JOIN Enrollment e
ON stu.Student_Id = e.Student_Id
JOIN Section sec
ON e.Section_Id = sec.Section_Id
JOIN Course c
ON sec.Course_No = c.Course_No
WHERE c.Description IN ('Systems Analysis', 'Project Managment') -- two values
GROUP BY stu.First_Name, stu.Last_Name, stu.Phone
HAVING COUNT(*) = 2 -- rows must have 2 instances
Upvotes: 2