Simple query question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Simple query question

Post by Shendemiar »

How do i select 20 records, those that are added last to the database?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Code: Select all

SELECT * FROM table ORDER BY record DESC LIMIT 20
Supposing you've got an auto incrementing record as an ID in your DB or a date for each DB entry, change the field for 'record'. I don't know if it's ASC or DESC without trying it myself, I always get confused.

HTH somehow though :)
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

jayshields wrote:

Code: Select all

SELECT * FROM table ORDER BY record DESC LIMIT 20
Supposing you've got an auto incrementing record as an ID in your DB or a date for each DB entry, change the field for 'record'. I don't know if it's ASC or DESC without trying it myself, I always get confused.

HTH somehow though :)
It's ASC. ASC = ascending = increasing; DESC = decending = decreasing. ;)
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

yeah im stupid, but not that stupid :)

i just forget which way it sorts dates sometimes :) like if it was ascending would it show the oldest date last?
Last edited by jayshields on Tue Nov 15, 2005 5:30 am, edited 1 time in total.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

My mother tongue is Dutch (although my French isn't that bad either) and i also had hard times to remeber it.

Here is the trick i used to remember it DESC descending - descendre (coming down in french)
Post Reply