Re: [GENERAL] getting the last N tuples of a query

2010-07-12 Thread Merlin Moncure
On Thu, Jul 8, 2010 at 9:09 PM, Kenichiro Tanaka wrote: > Hello. > > I agree Ben. > But,I try your question as an SQL puzzle. > Doses this SQL meet what you want? > > select * from wantlast offset (select count(*)-10 from wantlast); that works, but for any non trivial query it's not optimal becau

Re: [GENERAL] getting the last N tuples of a query

2010-07-08 Thread Kenichiro Tanaka
Hello. I agree Ben. But,I try your question as an SQL puzzle. Doses this SQL meet what you want? select * from wantlast offset (select count(*)-10 from wantlast); --test case create table wantlast(col1 int); insert into wantlast select g from generate_series(1,1000) as g; postgres=# select * f

Re: [GENERAL] getting the last N tuples of a query

2010-07-08 Thread Ben Chobot
On Jul 8, 2010, at 4:17 PM, Edmundo Robles L. wrote: > Hi! > > if a want the first 5,10,N tuples of a query (even without order) > i just have to do a: > select * from table limit 10; That does not get the first 10 tuples, it merely gets 10 tuples. The database is free to return whiche

[GENERAL] getting the last N tuples of a query

2010-07-08 Thread Edmundo Robles L.
Hi! if a want the first 5,10,N tuples of a query (even without order) i just have to do a: select * from table limit 10; but, What can i do to get the last 10 tuples ??? i try to do: select * from table limit -10; :-D but that query return 0 tuples . So, what is the right way to