Subject | SQL to renumber ID? |
---|---|
Author | diwic2 |
Post date | 2006-08-07T12:18:23Z |
Say you have this table:
a integer primary key
b integer primary key
c varchar(200)
And rows:
a b c
1 3 What
1 5 ever
1 9 some
2 1 very
2 3 useful
2 4 data
2 7 to
3 2 me
Now I want to renumber column b where a=2, so the result becomes:
a b c
1 3 What
1 5 ever
1 9 some
2 1 very
2 2 useful
2 3 data
2 4 to
3 2 me
The numbers should start at 1 while keeping the same internal order as
before, that is, the lowest number before the renumber will be nr 1,
the second lowest number becomes nr 2 etc.
Is there any smart SQL that would perform this renumbering?
// David
a integer primary key
b integer primary key
c varchar(200)
And rows:
a b c
1 3 What
1 5 ever
1 9 some
2 1 very
2 3 useful
2 4 data
2 7 to
3 2 me
Now I want to renumber column b where a=2, so the result becomes:
a b c
1 3 What
1 5 ever
1 9 some
2 1 very
2 2 useful
2 3 data
2 4 to
3 2 me
The numbers should start at 1 while keeping the same internal order as
before, that is, the lowest number before the renumber will be nr 1,
the second lowest number becomes nr 2 etc.
Is there any smart SQL that would perform this renumbering?
// David