ROW_NUMBER Without ORDER BY

Copper Contributor

HELLO,

I went to get only the first row from each group by [REF] 

 

Capture.PNG

1 Reply

The easiest way is to use a CTE = Common Table Expression, like

 

;WITH cte AS
    (SELECT ROW_NUMBER() OVER (...) AS row, Col1, ...
     FROM yourTable)
SELECT *
FROM cte
WHERE cte.row = 1