title: Postgres RETURNING clause with join and order
body: <p>I've got this query that updates some rows and returns the updated rows in the <code>RETURNING</code> clause. However, even though I've specified <code>ORDER BY mycolumn</code> in the inner query, the rows returned by <code>RETURNING</code> aren't ordered.</p>
  
  <pre><code>UPDATE mytable SET status = 'A'
  FROM
    (
      SELECT id FROM mytable
      WHERE status = 'B'
      ORDER BY mycolumn
      LIMIT 100
      FOR UPDATE
    ) sub
    JOIN jointable j ON j.id = sub.id
  WHERE mytable.id = sub.id
  RETURNING *
  </code></pre>
  
  <p>I tried putting an <code>ORDER BY</code> in the outer query, like after the <code>JOIN</code> or after the <code>WHERE</code>, but I get an error in both cases. How can I make it return the rows in the desired order?</p>
  
  <p>(A similar question was answered in <a href="https://stackoverflow.com/questions/25649976/update-returning-order-by-in-postgresql">Update Returning Order by in postgresql</a> but that doesn't include JOINs, only ORDER.)</p>