top Archives - Tech Insights Unveiling Tomorrow's Tech Today, Where Innovation Meets Insight Wed, 12 Oct 2022 10:15:15 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 https://i0.wp.com/reactconf.org/wp-content/uploads/2023/11/cropped-reactconf.png?fit=32%2C32&ssl=1 top Archives - Tech Insights 32 32 230003556 How to Find Top N records using SQL https://reactconf.org/how-to-find-top-n-records-using-sql/ https://reactconf.org/how-to-find-top-n-records-using-sql/#respond Wed, 12 Oct 2022 10:15:15 +0000 http://www.sqlneed.com/2022/10/how-to-find-top-n-records-using-sql/ In this article we will see how to Find Top N records using SQL Server. Top –N queries that limit the result set to a specific number of rows.  Top …

The post How to Find Top N records using SQL appeared first on Tech Insights.

]]>

In this article we will see how to Find Top N records using SQL Server. Top –N queries that limit the result set to a specific number of rows. 

Top N Without Grouping

Top N Without Grouping – in this query its get the department wise employee list with grouping.

Select top 3 d.GroupName,e.JobTitle, p.Firstname,p.Lastname  from [Person].[Person] p inner join [HumanResources].[Employee] e 
on(p.BusinessEntityID = e.BusinessEntityID) inner join  [HumanResources].[EmployeeDepartmentHistory] h
on(e.BusinessEntityID=h.BusinessEntityID) inner join [HumanResources].[Department] d on(d.DepartmentID=h.DepartmentID)

Example-2

Top N With Grouping

Top N With Grouping – Its fetch the department wise employee list with grouping.

select  d.GroupName,e.JobTitle, p.Firstname,p.Lastname ,
ROW_NUMBER() over (partition by d.groupname order by d.groupname asc) as department_rank 
from [Person].[Person] p inner join [HumanResources].[Employee] e 
on(p.BusinessEntityID = e.BusinessEntityID) inner join  [HumanResources].[EmployeeDepartmentHistory] h
on(e.BusinessEntityID=h.BusinessEntityID) inner join [HumanResources].[Department] d on(d.DepartmentID=h.DepartmentID)

The post How to Find Top N records using SQL appeared first on Tech Insights.

]]>
https://reactconf.org/how-to-find-top-n-records-using-sql/feed/ 0 2243