Quantcast
Channel: SQL Windowing Functions: Are the results ordered? - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 3

Answer by Artashes Khachatryan for SQL Windowing Functions: Are the results ordered?

$
0
0

This depends on the execution plan.

enter image description here

This query scans the clustered index, then sorts the results by the ordered column to be able to apply sequence object, and then returns the results to the client. That is why you see your final results ordered.

But if we look at the second execution plan (I forced the merge join just to show how the possibility of the final result to be in another order)

SELECT *FROM dbo.ProjectAuditTrialINNER MERGE JOIN (SELECT *, row_number() OVER (ORDER BY MajorVersion) AS rownum FROM dbo.Project) A ON A.ProjectID = ProjectAuditTrial.ProjectID

enter image description here

It this query our final results are not ordered by Window Functions ordering column.


Viewing all articles
Browse latest Browse all 3

Trending Articles