title: SQL Comparing a table with itself
body: <pre><code>Movie(title, year, director, budget, earnings)
  Actor(stagename, realname, birthyear)
  ActedIn(stagename, title, year, pay)
  CanWorkWith(stagename, director)
  </code></pre>
  
  <p>Find all pairs of stage names (renamed stagename1 and stagename2) such that the actor
  with stagename1 acted in the same movie as the actor with stagename2, but earned less
  for acting in that movie.</p>
  
  <pre><code>SELECT A.stagename, B.stagename
  FROM ActedIn A
  LEFT JOIN ActedIn B ON A.title = B.title AND A.year = B.year
            AND B.pay &gt; A.pay
  WHERE B.name IS NOT NULL
  </code></pre>
  
  <p>Not sure whether or not the WHERE B.name IS NOT NULL is valid</p>