i have a ¨id¨ column and another column ¨rootid¨. if certain condition is satisfied, the rootid field should have the same value as id (auto_increment) field. all this should be done at insertion. previously i had the logic thus:
select max(id)
based on this insert into table rootid=max(id)+1
i came across problem when i deleted some entries:
id rootid
== ======
5 5
6 6
7 7
this is what i normally got. but if i delete '6' the 7th entry becomes:
id rootid
== ======
5 5
7 6
the application gives wrong output. the workaround i had thought was:
1.insert with dummy rootid.
select max(id)
update rootid=max(id)
this requires 3 steps. is there any way i can reduce this?