I would like to have a Sql Server equivalent of the PostgreSQL distinct on ()
distinct on ()
a b ---- 1 1 1 2 2 2 2 1 3 3 select distinct on (a) * from my_
You can try ROW_NUMBER, but it can affect your performance.
ROW_NUMBER
;WITH CTE AS ( SELECT *, ROW_NUMBER() OVER(PARTITION BY a ORDER BY b) Corr FROM my_table ) SELECT * FROM CTE WHERE Corr = 1