SELECT t.student_id, t.course_id, t.grade
FROM takes t,
  (SELECT *
   FROM teaches
   WHERE professor_id=1) pcourses
WHERE t.course_id = pcourses.course_id;

SELECT p.lname, c.id
FROM professor p, course c, teaches t,
    (  SELECT student_id, course_id 
       FROM takes 
       WHERE grade >= 90  ) High 
WHERE 
t.course_id = c.id AND t.professor_id = p.id AND
c.id = High.course_id;

SELECT lname FROM student s
WHERE s.id IN (SELECT student_id FROM takes);

SELECT DISTINCT course_id
FROM takes outer_t 
WHERE EXISTS (
   SELECT * 
   FROM takes t, course c, offeredby do
   WHERE
	t.course_id = c.id AND
	c.id = do.course_id AND
    t.course_id <> outer_t.course_id AND
    do.department_id = 1 AND
    outer_t.student_id = t.student_id );

SELECT professor_id
FROM course c1, teaches t1
WHERE c1.id = t1.course_id AND
NOT EXISTS (
  SELECT *
  FROM course, teaches
  WHERE
	  course.id = teaches.course_id AND
      course.id <> c1.id AND
      professor_id = t1.professor_id);
