If you’re getting an error that reads “The function ‘ROW_NUMBER’ must have an OVER clause with ORDER BY” in SQL Server, it’s probably because you’re calling the ROW_NUMBER()
function without an ORDER BY
clause.
Window functions such as ROW_NUMBER()
require an OVER
clause, and that clause must have an ORDER BY
clause. If you’re getting the above error, there’s a good chance you’re providing an OVER
clause, but you’re omitting the ORDER BY
clause.
To fix this issue, add an ORDER BY
clause to the OVER
clause when calling the ROW_NUMBER()
function.