How do I change the order of entering the Mysql database?

Asked

Viewed 126 times

3

I want you to insert something into my Mysql (Phpmyadmin) and place it on top of the last post. Example:

Yesterday I inserted Nome: Pedro | Idade: 20 Anos

and he was at the top by being the first to be entered into the database

Today I wish to insert> Nome: João | Idade: 21 Anos

But he has to stay on top of Pedro, the order of the database view he needs to stay on top.

It is possible to do this?

1 answer

9


There is no such thing as what you are thinking about. The database is a data storage and query mechanism. You don’t establish how it will be stored, that’s his problem to do, the data is just there, no matter how. You enter what you need and it’s over, it doesn’t have the slightest relevance as it was inserted.

When you consult you need to say how you want the results to come back. Carrying the secret is in SELECT, there you will tell how the information is brought to you.

The question does not give details to help better, but it would probably be something like this:

SELECT * FROM tabela ORDER BY id DESC;

Behold working in the SQL Fiddle. Also put on the Github for future reference.

If you have a column called id which is auto-incremented. That’s usually how it does it. If you don’t have a column with a value that is guaranteed to be in ascending order you can’t do what you want in Mysql, this is probably a mistake anyway. Creating an index to better handle this order can be key to maintaining good performance on bases with many lines.

  • that way whenever I go to add a new person I need to use this command there is how I leave permanently in DESC?

  • @Kleyner actually has nothing to do with inserir user and yes at the time of the query. You will enter the data normally, without worrying about any order, at the time of displaying the data select, that you will use the DESC, thus, the results will be displayed in descending form. I conclude by reaffirming: Do not worry about the order that records are entered, the important thing is to pull this data from the database.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.