title: Relational algebra with multiple joins
body: <p>I'm trying to write the following question as relational algebra:</p>
  
  <p>Pnr and pname for all products which have a substitute product with a lower price.</p>
  
  <p>The relations I have are these:</p>
  
  <pre><code>Product(Pnr, Pname, Price) //Product info
  Substprod(Pnr, Subst-Pnr) //Product which can replace other products
  </code></pre>
  
  <p>If I do it in SQL it would look something like this:</p>
  
  <pre><code>SELECT p.pnr, p.pname
  FROM Product p1, Substprod s, Product p2
  WHERE p1.pnr = s.pnr
  AND s.subst_pnr = p2.pnr
  AND p1.price &gt; p2.price
  </code></pre>
  
  <p>But I can't see how I can get the same result in relational algebra. I'm guessing that I need to do a 3-way-join here too, but having trouble with the condition that one price on a particular product should be lower than its substitute.</p>