Hi All,
I have a douts about ROW_NUMBER() funcction using sql server,
i have a two sample query like below,
My problem is my fist query is working fine because its avoiding duplicate datas, compare to my actual table data
But my second query is not avoiding duplicate values as well as my SN number always showing 1
but i want to show my SN number should be autoincrement.
So how can i achieve this solution, please help me.
My Actual table data is:
id
----
ajson1
ajson1
ajson3
ajson4
query 1:
select DISTINCT id from json order by id asc
OUTPUT:
id
-----
ajson1
ajson3
ajson4
query 2:
SELECT
(SELECT DISTINCT ROW_NUMBER() OVER(ORDER BY id ASC)) AS SN,
id
FROM json
OUTPUT:
SN id
-- -----
1 ajson1
1 ajson1
1 ajson3
1 ajson4
thanks in advance