Re: Help- query for last x items

From: Matt Marrow [LOGICA][dc] <mmarrow_at_zeus>
Date: 1996/09/16
Message-ID: <51k38b$h68_at_zeus.mobile.com>#1/1


The only problem here is that the order by is done on the query after the rownum is generated (or however you'd phrase that better)

Thus you would only get a sorted list of whatever the first one hundred rows the query returned, not the last 100 (if X were to be 100)

Hope this helps

Matt

mmarrow_at_pacbell.mobile.com

All views my own so they may be wrong.

Shay Shmelzer (shmelzer_at_johnbryce.co.il) wrote:
: Jason Yeoung Zien wrote:
: >
: > Hi,
: >
: > Can anyone tell me how to efficiently query for the last X
: > items in a sorted subset?
: >
: > For example my initial attempt was,
: >
: >
: > select * from access_log where type='user'
: > where (rownum < X) and (rownum> X-100) /* <--- this is wrong */
: > order by access_date desc
 

: Simply reverse(asc) your order by and select the first 100 .(rownum
: <101);
: this will give u the same as the last 100 with a desc order by .
 

: --
: ++++++++++++++++++++++++++++++++++ |\/\/\|
: Shay Shmelzer | |
: E-mail : shmelzer_at_johnbryce.co.il OO )
: Phone : 972-3-5765647 ISRAEL c |
: Organization: John Bryce Systems /___/ |
: ++++++++++++++++++++++++++++++++++ ) (
  Received on Mon Sep 16 1996 - 00:00:00 CEST

Original text of this message