NameSilo

MySQL ORDER by Question

Spaceship Spaceship
Watch

JsteRmX

Established Member
Impact
2
By default when you query the DB and have it display the selected data, it will just show it to you in the order it was entered into the database.... Meaning the first record will be the first in the list. I want to reverse this. I want the newest record to show on the top. What would I Order by in my sql query? I do not have a date added column in my database, so this is not really an option. And using Order by desc is for alphabetical order. I need it to just reverse the default way. Can anyone help? Thanks!

wow nevermind everyone. I found a solution. It jsut came to me right after posting my question.

I do have an ID field in my table, so i am just ordering by that, desc. So the last number (or really the newest one) appears on top.

:tu:
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
the id .
 
0
•••
select * from anytable order by id desc

hope it helps
 
0
•••
if you read his post fully you will see he already got his answer and posted it into the same post.
 
0
•••
Please note that the 'gaps' in the ID sequence may be reclaimed by mySQL or filled in manually. If you are looking for the true last added/updated record it may be a good idea to add a timestamp column and sort desc on it.
 
0
•••
wow nevermind everyone. I found a solution. It jsut came to me right after posting my question.

:)
 
0
•••
lol! just read the post halfly...sorry :D
 
0
•••
lol thanks for all the replies though.

I thought i posted that update to a REPLY, not in the same post! sorry guys! I guess that was kind of confusing. ..... i could have sworn i hit 'reply' though. hmmmmmm :-/ maybe i am going crazy, hehe.
 
0
•••
If you double post in the same day, it adds it to your previous post.
 
0
•••
oh I see, obviously I didnt know that... thanks for the info.
 
0
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back