7

I have a view with something like 150 columns and I want to add an Id column to that view. Is it possible not to write all the column names in the over (partition by... ) statment?

something like this:

row_number over (partition by *) As ID?
Sanushi Salgado
  • 1,195
  • 1
  • 11
  • 18
Toto88
  • 129
  • 3
  • 11

1 Answers1

6

If you want to add a row number to the view, don't you just want an order by with no partition?

If so, you can use one of the following, depending on the database:

select row_number() over ()
select row_number() over (order by NULL)
select row_number() over (order by (select NULL))

Your approach would be enumerating identical rows, not providing a row number over all rows.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786