How to insert a specify row in mysql?

305
June 29, 2017, at 05:31 AM

Suppose I have a table t1 like

mysql> select * from t1;
+------+-------+------+
| id   | level | gap  |
+------+-------+------+
|    1 |     6 |   50 |
|    1 |     5 |   10 |
|    2 |     5 |   12 |
|    2 |     5 |   10 |
|    3 |     8 |    4 |
|    3 |     9 |    1 |
|    3 |     9 |    3 |
|    3 |     7 |    2 |
+------+-------+------+

I want to insert a row (3,6,7) into here.I mean it is below in first 5 row.

Is it possible in mysql?

Answer 1

Just do

INSERT INTO TABLE t1 (id, level,gap) VALUES (3,6,7) 

Records in a table do not have a prescribed order. The order has to be defined during a SELECT by supplying a suitable ORDER BY clause.

So, if you want the new record to be listed in 5th position use ORDER BY id, level.

Rent Charter Buses Company
READ ALSO
How would I retrieve the second result with query builder?

How would I retrieve the second result with query builder?

I am trying to retrieve the second result of this query (which works successfully):

250
MySQL Master/Slave Replication

MySQL Master/Slave Replication

I was trying to find some answers about this, and I couldnt find any possible post with similar/same problemPlease excuse me If I somehow missed it

318
How to create html table from mysql “GET” request in Flask framework

How to create html table from mysql “GET” request in Flask framework

I have set up a Flask app that is connected to my mysql databaseIt can POST request fine and also GET

312
MySQL query to search for items with parent items tag

MySQL query to search for items with parent items tag

So I followed what they did here: MySQL query to search for items with certain tags

239