yeny314 yeny314 - 1 month ago 5
MySQL Question

Nested subQueries with comparing dates

Is this right? I feel like my logic is off here but I need to list students who started later than at least one student enrolled in 'IT' department.

SELECT studentid, year
FROM enrolled, course
WHERE program = 'IT' and year >= ALL (
SELECT year FROM enrolled);


enrolled(studentid, courseID, year)
course(courseid, department)


I believe everything is right except the where part




Sorry, I gave out the wrong schema, it was suppose to be from

Student(sid, started, program)

but I believe it now works with this, thank you

SELECT sid, started
FROM student
WHERE started > (
SELECT MIN(started)
FROM student
WHERE program = 'IT');

Answer

Take it in steps

The first student to be in "IT" (guessing there is a column named program)

SELECT MIN(year)
FROM enrolled
WHERE program = 'IT'

List students who started later than at least one student enrolled in 'IT' department.

SELECT studentid, year
FROM enrolled 
WHERE year > (
  SELECT MIN(year)
  FROM enrolled
  WHERE program = 'IT'
)
Comments