Mysql Insert data into a table, satisfied with the question?

I found a wear problem with my MySQL DB.

When I insert new data into it, the way to organize the data is similar to the stack, for example

4 (newest)

3

2

1 (oldest) ...

how can i do it this way?

1 (newest)

2

3

4 (oldest)

thank you all.

+4
source share
2 answers

SQL standards specifically indicate that tables do not have a โ€œnaturalโ€ order. Therefore, the database engine can return a query without ORDER BY in any order. An order can change from one request to another, because most engines prefer to return data in any order so that they can receive it most quickly.

Therefore, if you want the data to be in a specific order, you must include the column in your table whose job is a proxy for the order in which you added records to the table. Two common ways to do this is to use the auto-increment field, which will be in numerical order from the oldest to the latest record, and the TIMESTAMP column, which does just what it says. When you have such a column, you can use ORDER BY ColumnName in your search to get an ordered set of results.

+1
source
SELECT * FROM TABLE ORDER BY ID 

You must remember that when viewing / selecting data from a table without any ORDER BY specified, no specific order is executed .

The way you look at the data (disordered) can be caused by any of many facts (database engine, schema, page storage, page fragmentation, indexes, primary keys or just optimization of the execution plan).

+2
source

All Articles