I'm trying to understand ROW_NUMBER from MSSQL and making some experiences.
I have these two snippets:
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;
and
select top 20 * from dbo.ProcessoInstanciaFonte as p order by p.DtDistribuicao
They both should return the same rows but aren't. What is the problem?