From: | Jeff Davis <jeff95350(at)yahoo(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: [GENERAL] SELECT LIMIT and the last rows of a query |
Date: | 2000-02-20 02:12:37 |
Message-ID: | 20000220021237.16270.qmail@web3002.mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Try the folowing querys:
=> SELECT * FROM myTable ORDER BY myColumn DESC LIMIT
5;
That is exactly the last 5 rows of the query:
=> SELECT * FROM myTable ORDER BY myColumn;
Unfortunately, the tuples are in the opposite order
(thanks to DESC).
If the opposite order is a problem, I guess you could
do a workaround, like this:
=> CREATE VIEW myView AS SELECT * FROM myTable ORDER
BY myColumn DESC LIMIT 5;
=> SELECT * FROM myView ORDER BY myColumn ASC;
=> DROP VIEW myView;
I can't think of any problem with the second one
except speed, but i don't think there are any other
ways to do it; if there are I would like to know.
Hope it helps,
Jeff Davis
--- mathprof(at)bigfoot(dot)com wrote:
> The command:
>
> SELECT (query) LIMIT m,n
>
> gives m rows of the query's response, starting at
> row n+1, while
>
> SELECT (query) LIMIT m
>
> gives the first m rows of the query's response
> (starting at row 1).
>
> Is there any easy way to get the *last* m rows of a
> query? I tried:
>
> SELECT (query) LIMIT 5, -5
>
> in an attempt to get the last 5 rows, but this gives
> a parser error. Any
> other thoughts?
>
>
> ************
>
>
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com
From | Date | Subject | |
---|---|---|---|
Next Message | David May, Powered by FreeBSD, Somewhere in the Outback | 2000-02-20 05:05:36 | [Q] Tcl, ODBC and Postgresql. |
Previous Message | Tom | 2000-02-19 23:05:12 | Backend terminated abnormally error ? |