select top 10 Id, Name, Address from Employee
where DepartmentId = 5
The above sql statement will provide you top 10 records from Employee table but there might be the scenario where you have to retrieve only top 10 records but also you want to know how many records are still available. To do that there are multiple ways like but the most appropriate, performance oriented and without calling a separate call to SQL table is mention below.
select top 10 Id, Name, Address, count(*) over(partition by 1) as TotalRows
from Employee
where DepartmentId = 5
No comments:
Post a Comment