D
D
denislysenko2022-03-03 13:20:13
SQL
denislysenko, 2022-03-03 13:20:13

How to add numbered results to select?

I have a table with no id column.

How can I add an id column without using DDL statements. I need to do this in a select call

. I know that window functions can be used. For example:
ROW_NUMBER() OVER (ORDER BY name) AS id

But here it is necessary to specify sorting, I just want the id column to be added, which would go in order from the table that I already have.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Akina, 2022-03-03
@denislysenko

I just want to add an id column that would go in order from the table that I already have.

Break off.
There is no order in the table, the table is an unsorted heap. The order in which the records were inserted into the table is nothing more than temporary visibility. And the order that is issued now, easily has every right to change tomorrow. And it will definitely change - moreover, according to the law of great meanness at the most inconvenient moment for you.
Sorting is not a show off, but a conscious necessity. The only way to get a deterministic result.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question