If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > retrieve one before the last entry

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-26-09, 07:41
danny_brazil danny_brazil is offline
Registered User
 
Join Date: Jul 2009
Posts: 19
retrieve one before the last entry

Hello
i understand how to retrieve the last entry with DESC and LIMIT 1

but is there any way to get the second to last entry ?

Danny
Reply With Quote
  #2 (permalink)  
Old 08-26-09, 08:35
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
It isn't particularly efficient but if you're comfortable with using DESC and LIMIT then this might work:

Code:
select *
from (  select *
        from table
        order by main_field desc
        limit 2 ) tmp
order by main_field
limit 1
Reply With Quote
  #3 (permalink)  
Old 08-26-09, 09:55
danny_brazil danny_brazil is offline
Registered User
 
Join Date: Jul 2009
Posts: 19
got it

some one helped me like that and its working

Go exactly like DESC and LIMIT 1, but instead of LIMIT 1 do this:

LIMIT 1,1

(LIMIT 1 actually is LIMIT 0,1)

thanks
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On