How i can make newly inserted records stay at the top of older records

When i insert a new record in a database table it is displayed below older records in the table.

i.e
1 first inserted record
2 second inserted record
3 third inserted record

How can i make the new records that i insert in a database table to be displayed as the newest inserted record at the top of other records that i have inserted.

i want it displayed this way

3 third inserted record
2 second inserted record
1 first inserted record

thanks

Is there a special reason why you want the rows in the database table to be in this order? Because when you retrieve the data from the database table, you can order it in any way you want before you display it.

2 Likes

You can use ORDER BY in your SELECT query.
For example:-

SELECT * FROM records ORDER BY date DESC

If date is a timestamp of the insertion they will be in that order descending from the most recent.

2 Likes

I only want the rows to be in that order, newest at the top, i don’t know how to go about it.
Just let me know how i can make it be in that order when it is being displayed

Do what @SamA74 suggested, or if you have IDs as primary keys, they will increment each time a new record is inserted, so you could use ORDER BY id DESC also.

1 Like

i have primary key

Thanks to you all, worked as expected

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.