title: Row_Number() with union query
body: <p>I have an sql query that returns rows from two tables with same column names. I need a row number of all records in a complete result set.</p>
  
  <p>Following is the query </p>
  
  <pre><code>select Id, VersionNumber from documents where id=5 
  Union all  
  select Id, VersionNumber from versions where id=5
  order by VersionNumber desc
  </code></pre>
  
  <p>How should it be done?</p>
  
  <p><strong>EDIT:</strong> And what if I only need to return a row_num where VersionNumber is lets say 5.</p>