Thread: How Can I limit the select result ?

How Can I limit the select result ?

From
"¹Ú¹Ì·æ"
Date:
I want to select like this...

select * from any_table where table_field > any_no limit 10 order by
table_field DESC;

I want to select more than 1000 rows.
But, I want to view only 10 from maximum to maximum -10.

How can I ?

I want to make the search engin using Postgresql.
If more than 10000 rows, there's hard to query, I think...
Does anybody know about this ?

Please help me.


Re: [SQL] How Can I limit the select result ?

From
Maarten Boekhold
Date:
On Fri, 24 Jul 1998, =?UNKNOWN?Q?=B9=DA=B9=CC=B7=E6?= wrote:

> I want to select like this...
>
> select * from any_table where table_field > any_no limit 10 order by
> table_field DESC;
>
> I want to select more than 1000 rows.
> But, I want to view only 10 from maximum to maximum -10.
>
> How can I ?
>
> I want to make the search engin using Postgresql.
> If more than 10000 rows, there's hard to query, I think...
> Does anybody know about this ?

use cursors:

begin;
declare C cursor for
    select * from any_table
        where table_field > 10
    order by table_field DESC;
move forward 4590 in C;
fetch fetch 10 in C;
end;

I don't know how to move to the end of the result set. Maybe it's possible
to use 'move backward 10 in C' and then 'fetch forward 10 in C', you'll
have to try.

Maarten

_____________________________________________________________________________
| TU Delft, The Netherlands, Faculty of Information Technology and Systems  |
|                   Department of Electrical Engineering                    |
|           Computer Architecture and Digital Technique section             |
|                          M.Boekhold@et.tudelft.nl                         |
-----------------------------------------------------------------------------


Re: [SQL] How Can I limit the select result ?

From
Guido Piazzi
Date:
On Fri, 24 Jul 1998, ¹Ú¹Ì·æ wrote:

> I want to select like this...
>
> select * from any_table where table_field > any_no limit 10 order by
> table_field DESC;
>
> I want to select more than 1000 rows.
> But, I want to view only 10 from maximum to maximum -10.

Try using a cursor:

begin;
declare bingo cursor for
select * from any_table
where table_field > any_no
order by table_field DESC;
fetch 10 in bingo;
end;

And if I mistyped something... read the man pages.
Regards,
 -Guido-