if on oracle, a top n looks like this

SELECT * FROM
(
     SELECT field1, field2,  ... , fieldn
      FROM table
      ORDER BY id DESC
}
WHERE rownum < 6

assuming the ID column is a sequential number, this would work, eh?

SELECT  field1, field2,  ... , fieldn
FROM table
WHERE id > (SELECT Max(id)-5 FROM table)

Doug

----- Original Message -----
From: Charlie Griefer <[EMAIL PROTECTED]>
Date: Thu, 30 Sep 2004 10:40:39 -0700
Subject: Re: last 5 entries of query
To: CF-Talk <[EMAIL PROTECTED]>

SELECT TOP 5 ... [columns]
FROM [table]
ORDER BY id DESC

On Fri, 1 Oct 2004 05:36:50 +1200, Mark Henderson <[EMAIL PROTECTED]> wrote:
> I'm just wondering if there is an easier way to display only the the last 5
> entries of a query without having to use, in my case, max(id) and then
> subtracting 5. This means I have to do a couple of queries to get the
> resulting output and I thought it might be possible to do everything inside
> the one query.
>
> TIA
> MarkH
>
>________________________________
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to