hehe
hehe

Reputation: 215

Is there a way to add ROW_NUMBER() without using OVER (ORDER BY ...) in SQL

Is there a way to add ROW_NUMBER() simply based on the default row order without using OVER (ORDER BY ...)?

Upvotes: 2

Views: 3548

Answers (2)

For PostgreSQL and MYSQL 8.0

row_number()over() 

For SQL Server and oracle it will be:

row_number()over(order by (select null))

But this without mentioning proper order by clause it's not guaranteed to have same row number for a column everytime.

Upvotes: 1

Stu
Stu

Reputation: 32609

There is no implicit ordering to rows in a table, it is a logical unordered set.

however you can do row_number() over (order by (select null))

As suggested by Itzik Ben-Gan from his book on window functions.

Upvotes: 2

Related Questions