Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Difference between ROW_NUMBER() and ORDER BY...DESC

$
0
0
Hi guysThis is just for interest sake from my side. I have the following code entered into Adventureworks2014:SELECT p.FirstName ,p.LastName ,ROW_NUMBER() OVER(ORDER BY s.SalesYTD DESC) AS 'RowNumber' ,s.SalesYTD ,a.PostalCodeFROM [Sales].[SalesPerson] s INNER JOIN [Person].[Person] p ON s.BusinessEntityID = p.BusinessEntityID INNER JOIN [Person].[BusinessEntityAddress] ba ON p.BusinessEntityID = ba.BusinessEntityID INNER JOIN [Person].[Address] a ON a.AddressID = ba.AddressIDWHERE s.TerritoryID IS NOT NULL--ORDER BY s.SalesYTD DESCAND get the same output if I uncomment the ORDER BY s.SalesYTD DESC line and comment out ROW_NUMBER() OVER(ORDER BY s.SalesYTD DESC) AS 'RowNumber'. I hardly ever use the ROW_NUMBER() function, so is there a difference using this function and ORDER BY...DESC?Like I said, this is not something I am working with, but would just like to learn more about the rank functions, as I never get to use it in my working environment.

Viewing all articles
Browse latest Browse all 3145

Trending Articles