title: row_number() and order by on column not in results
body: <p>I have a case where I would like to use <code>row_number()</code> is SQL Server to get back unique numbers in two related queries on the same table. The problem is that I don't have a column which appears in both queries which I can rely upon to be unique, although both queries run against the same table with a single column primary key (which I'll call pk here) and the same <code>WHERE</code> clause. So both queries are in the form</p>
  
  <pre><code>SELECT row_number() OVER(ORDER BY table1.pk ASC) as my_id, .....
    FROM table1, table2
   WHERE table1.pk = table2.fk and ....
  </code></pre>
  
  <p>but <code>table1.pk</code> only appears in the result set of one of these queries. Can I rely on both of these queries returning the rows in the same order (relative to the rows in table1)? If not, can someone suggest another approach? These <code>SELECT</code> are the input to <code>INSERT</code> statements, so I don't have a lot of leeway as to the result columns.</p>