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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The last n records 2

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I need to get the last n records from a table in ASC order.
I know I can query the count and then limit another query to the last n.
I could also query the first n in DESC order and then flip them in an array.

Is it possible to get the last n records in ASC order with a single query?

Keith
 
How about a subquery. This works for me
Code:
select * from (SELECT * FROM `locations` WHERE 1 order by zip desc limit 10) inTable order by zip asc

-----------------------------------------
I cannot be bought. Find leasing information at
 
locations is the name of your table

inTable is the table alias of the derived tale produced by the subquery

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top