I am trying to select DISTINCT strings from a view using ROW_NUMBER () OVER for swap. When I switched the ORDER BY field from SMALLDATETIME to INT, I began to get strange results:
SELECT RowId, Title, HitCount FROM ( SELECT DISTINCT Title, HitCount, ROW_NUMBER() OVER(ORDER BY HitCount DESC) AS RowId FROM ou_v_Articles T ) AS Temp WHERE RowId BETWEEN 1 AND 5
This query returns:
RowId | Title | HitCount
The results are obviously not in the correct order. I'm not sure what the problem is, but when I uninstall DISTINCT, it arranges them correctly.
Thanks.
source share