Question

I have a requirement like below. I have table like the below one :

ID  SID  VID  VTXT
1    10  v_5   Five
1    10  v_5   asd
2    11  v_7   Seven
2    11  v_7   seven
3    12  v_9   NINE
3    12  v_9   Nine
3    12  v_9   nine

I need the output as :

ID  SID  VID  VTXT
1    10  v_5   Five
2    10  v_5   asd
1    11  v_7   Seven
2    11  v_7   seven
1    12  v_9   NINE
2    12  v_9   Nine
3    12  v_9   nine

Please help me with this issue.

Was it helpful?

Solution

i don't know the syntax of tags you made if this is for sql-server it'd be

update table 
set ID=(select rn=row_number() over(partition by ID order by ID) from table)

OTHER TIPS

You mean you want to order the results like that?

Order by SID, ID

You can use the ROW_NUMBER() function with Partition By clause

Here is the sample

SELECT row_number() AS ID, 
    SID, 
    VID, 
    VTXT
FROM VTable;

Partition By enables renumbering of rows in the group defined by each combination of PARTITION BY clause column values.

You can refer to SQL Row_Number samples at referred document hoping to be useful

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top