How to insert a row into a table between two existing rows in Sql

I have a table with 9 records, but I want to insert a row between the 5th and 6th records.

+4
source share
2 answers

if you insist on

UPDATE mytable SET id = id + 1 where id > 5 ORDER BY id ASC insert into mytable (id,..) values (6,...) 
+10
source

In general, you do not insert a row at a specific place in the table.

If the line "order" is significant and has some special semantics, the data reflects this with the corresponding column in the table structure.

Then use SELECT ... ORDER BY ... to sort the rows.

+3
source

Source: https://habr.com/ru/post/1395228/


All Articles