Re: [GENERAL] SELECT LIMIT and the last rows of a query
От | Jeff Davis |
---|---|
Тема | Re: [GENERAL] SELECT LIMIT and the last rows of a query |
Дата | |
Msg-id | 20000220021237.16270.qmail@web3002.mail.yahoo.com обсуждение исходный текст |
Список | 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@bigfoot.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
В списке pgsql-general по дате отправления: