title: SELECT from One Table an Element that Occurs Multiple Times in Another Table
body: <p>I need to find out the names of the students who have enrolled in <em>at least</em> two courses.</p>
  
  <p>Creating the two tables:</p>
  
  <pre><code>CREATE TABLE Student (
    StudentID varchar(20) PRIMARY KEY,
    FirstName varchar(15),
    LastName varchar(30),
    Sex varchar(6),
    DOB date,
    Email varchar(40)
  );
  
  CREATE TABLE Enrols (
    StudentID varchar(20),
    CourseID varchar(20),
    CONSTRAINT Student_Course PRIMARY KEY (StudentID,CourseID),
    FOREIGN KEY (StudentID) REFERENCES Student(StudentID),
    FOREIGN KEY (CourseID) REFERENCES Course(CourseID)
  );
  </code></pre>
  
  <p>My (unsuccessful) attempt:</p>
  
  <pre><code>SELECT DISTINCT Student.FirstName,
    Student.LastName,
    Enrols.CourseID,                  
    COUNT (Student.FirstName) AS NumberOfNames
    FROM Student
    INNER JOIN Enrols
      ON Student.StudentID = Enrols.StudentID
    WHERE COUNT(Student.Firstname) &gt;= 2;
  </code></pre>