Ranking the rows using ROW_NUMBER()
Hi Guys, here i m going to explain how you can give rank to the rows on the basis of column's information and by creating Partition. suppose you have a table, like:- M_Emp EmpId EmpName E001 GAGAN E001 GAGAN E001 GAGAN E002 AMAN E002 AMAN E003 NAMAN Now Execute following query :- SELECT EmpId, EmpName, ROW_NUMBER()OVER(Partition by EMPID ORDER by EMPID) RowId FROM M_Emp Output :- EmpId EmpName RowId E001 GAGAN 1 E001 GAGAN 2 E001 GAGAN 3 E002 AMAN 1 E002 AMAN 2 E003 NAMAN 1 This will results in the ranking of rows on the basis of column information. I hope you understand the logic/syntax behind. basically It is used to perform any rank based operation.