Written By:- Isha Malhotra (Software Developer)
Note: -if you find this article helpful then kindly leave your comment
Rank Function in SQL server
SQL server also supports Some rank function also. To use the rank function you must have to assign it to Over function. In over function we give the order in which records will be Shown.
These functions are Following:-
1. Rank ()
This function is used to Define the rank according to the order which we set in order by clause.
See the following records Of temp table:-
In this table there are Two records which having the same salary i.e. 1000.
select *, RANK() over( order by salary asc) as rank from emp;
as I am showing records in ascending order then it will show the output like that:-
As you can see that it gives same rank to the same rcords according to its order.
This function is used to count the row in a table.
select *, row_number() over(order by salary asc) as 'Row Number' from emp;
this query will show the Output as follows:-