Is it possible to insert data into the middle of a table using the INSERT command?

Example:

INDEX | SOME_DATA

1 | some_data1

3 | some_data3

4 | some_data4

5 | some_data5

I want to add INSERT to add ---> 2 | some_data2. Is there an SQL command or some way to do this?

[edit]
OK. Perhaps if I explain everything I want to do, you will understand why I'm trying to do what I want. I am creating a web admin page in php that just displays data from a database table. Now these displayed lines are draggable. For example, you can drag row number 2 to say row number 4. now in the mouseup event i want to save the new order in the database.

1 | data1 ------------------------- > 1 | data1
2 | data2 ------- Drag ----- > 3 | data3
3 | data3 ------------------------- > 4 | Data4
4 | data4 ------------------------- > 2 | data2
 . ? INDEX , . , . 3 2, 4 3 2 4. Thats too many sql updates ( ). №2 .

+3
4

, , , , .

, , - - , .

, " sql"? , MySQL, index, ( ).

, , . ( ), :

CREATE INDEX row_index_index ON `some_table` (`index`);

"" "", MySQL.

+1

; . , select.

: , "". float, . , "A" "" "1", "B" "order" "2", "C", "A" "B", "", 1.5 (1 + 2/2.0). , "" "", , . - , "" .

+6

, :

INSERT INTO some_table (index, some_data) VALUES (2, 'some_data2')

, , , :

ALTER TABLE some_table ORDER BY index;

, . , , ORDER BY . .

+5

, .

insert into yourtablename (index, some_data) values (2, "some_data2");

, , . , .

+2

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


All Articles