title: sql: first row after the last row with a property
body: <p>I would like to write a query that returns the first row immediately after the last row with a given property (ordered by id). Id's may not be consecutive.</p>
  
  <p>Ideally it would look something like this:</p>
  
  <pre><code>...
  JOIN (select max(id) id from my_table where CONDITION) m
  JOIN (select min(id) from my_table where id &gt; m.id) n
  </code></pre>
  
  <p>However, I can not use identifier <code>m</code> in the second subselect.</p>
  
  <p>It is possible to use nested queries in nested queries, but is there an easier way?</p>
  
  <p>Thank you.</p>