title: How to properly use the Sql Server ROW_NUMBER function with ordered queries?
body: <p>I'm trying to understand ROW_NUMBER from MSSQL and making some experiences. </p>
  
  <p>I have these two snippets:</p>
  
  <pre><code>SELECT * 
      FROM 
      (
          SELECT *,
          ROW_NUMBER() OVER (order by p.DtDistribuicao) AS RowNumber
          FROM ProcessoInstanciaFonte as p
      ) as q 
  
  WHERE q.RowNumber BETWEEN 1 AND 20;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>select top 20 * from dbo.ProcessoInstanciaFonte as p order by p.DtDistribuicao
  </code></pre>
  
  <p>They both should return the same rows but aren't. What is the problem?</p>