Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using LIMIT with SELECT queries

Status
Not open for further replies.

buzznick

IS-IT--Management
Dec 29, 2004
39
US
Hi All,

I have a problem using the LIMIT statement in MySQL. Basically I want to limit results to a number such as 200. However, this works fine except it returns the *first* 200 records it finds. What I want is the *last* 200 records because I need to examine the latest records.

here's an example of how the query looks now:

SELECT recordid FROM allRecords WHERE userID = $uID ORDER BY recordid LIMIT 0, 200

What do I need to change/add to make it pull the latest records and not the first 200?

Thanks,
Nick
 
Hi Tony, wow that was fast!!!

So what does the DESC do? Also, I noticed that the first figure after LIMIT has now gone? Is that what makes it get the *latest* records?

Thanks!
Nick
 
DESC means "descending"; it sorts the records into descending order, so that the first 200 records are really the last 200. LIMIT 200 is the same as LIMIT 0,200 . The 0 is the number of records to be skipped before the required 200.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top