title: Which of the following can you NOT do in relational algebra?
body: <p>tldr; Which of the three below can you not write in RA?</p>
  
  <p>Our prof asked us to write 3 SQL queries.  He then asked us which of them could not be written in Relation Algebra.  They are as follows:</p>
  
  <p>Given the following 3 tables:   </p>
  
  <pre><code>Students (sID, sName);              (Primary Key sID)
  Courses (cID, cName);               (Primary Key cID)
  Enrolled (sID, cID, sectID, grade)  (Primary Key sID, cID)
  where      foreign key (sID) references Students,  
             foreign key (cID) references Courses. 
  </code></pre>
  
  <ol>
  <li>Find the largest student ID.  </li>
  <li>Get a class list (consisting of 〈sID, sName〉) for COMP 4380, and arrange the records in the list in alphabetical order of sName. (He just wants all the students who have ever taken the course).</li>
  <li>Count the number of students enrolled in each course (identified by course ID). </li>
  </ol>
  
  <p>So we have:</p>
  
  <ol>
  <li>A query involving finding the maximum in a column of integers.</li>
  <li>A query involving sorting the result in alphabetical order.</li>
  <li>A query involving counting multiple groups.</li>
  </ol>
  
  <p>I've managed to write an RA statement for #1 (<a href="https://stackoverflow.com/questions/5493691/how-can-i-find-max-with-relational-algebra" title="Details here">Details here</a>) so I know that is not it.  I'm not sure about 2 and 3 however.  How could you sort with the RA operations?  How could you count multiple groups?  I would <em>guess</em> 3 is possible since RA can be extended to have count as an aggregate function.</p>
  
  <p>Here are the SQL statements I came up with to answer my prof's original question:</p>
  
  <pre><code>SELECT max(sID) 
  FROM Students
  
  SELECT sID, sName
  FROM Enrolled INNER JOIN Students
  WHERE cID="COMP 4380"
  ORDER BY sName
  
  SELECT count(sID), cID
  FROM Enrolled
  GROUP BY cID
  </code></pre>
  
  <p>I haven't been able to write 2 and 3 in RA.</p>