Обсуждение: top predicate

Поиск
Список
Период
Сортировка

top predicate

От
"Karen Hill"
Дата:
It seems PostgreSQL doesn't have a TOP Predicate.  Why is that?  Here
is an example:

SELECT TOP 10 products from sales;


Re: top predicate

От
Tom Lane
Дата:
"Karen Hill" <karen_hill22@yahoo.com> writes:
> It seems PostgreSQL doesn't have a TOP Predicate.  Why is that?

It's not in the SQL standard.  If we were to implement something like
what I think you're asking for (your example is way underspecified),
it'd probably look like SQL2003's window functions.

            regards, tom lane

Re: top predicate

От
Jan de Visser
Дата:
On Thursday 11 May 2006 16:34, Karen Hill wrote:
> It seems PostgreSQL doesn't have a TOP Predicate.  Why is that?  Here
> is an example:
>
> SELECT TOP 10 products from sales;

Just for my understanding: This would return the 10 products with the most
matching sales rows, right?

jan


--
--------------------------------------------------------------
Jan de Visser                     jdevisser@digitalfairway.com

                Baruk Khazad! Khazad ai-menu!
--------------------------------------------------------------

Re: top predicate

От
"Joshua D. Drake"
Дата:
Karen Hill wrote:
> It seems PostgreSQL doesn't have a TOP Predicate.  Why is that?  Here
> is an example:
>
> SELECT TOP 10 products from sales;


Just use:

SELECT product from sales limit 10

OR

SELECT products from sales order by products desc limit 10;

Joshua D. Drake


>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
>                http://archives.postgresql.org
>


--

            === The PostgreSQL Company: Command Prompt, Inc. ===
      Sales/Support: +1.503.667.4564 || 24x7/Emergency: +1.800.492.2240
      Providing the most comprehensive  PostgreSQL solutions since 1997
                     http://www.commandprompt.com/



Re: top predicate

От
Ben
Дата:
Have you tried using the LIMIT clause?

select porducts from sales limit 10;

http://www.postgresql.org/docs/8.1/interactive/queries-limit.html

On Thu, 11 May 2006, Karen Hill wrote:

> It seems PostgreSQL doesn't have a TOP Predicate.  Why is that?  Here
> is an example:
>
> SELECT TOP 10 products from sales;
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
>               http://archives.postgresql.org
>

Re: top predicate

От
"Karen Hill"
Дата:
Tom Lane wrote:
> "Karen Hill" <karen_hill22@yahoo.com> writes:
> > It seems PostgreSQL doesn't have a TOP Predicate.  Why is that?
>
> It's not in the SQL standard.  If we were to implement something like
> what I think you're asking for (your example is way underspecified),
> it'd probably look like SQL2003's window functions.
>

Hi Tom,

The TOP predicate seemed to be really common in some other RDBMS.  I
guess it isn't in the standard since oracle seems to be missing it in
9i.  Maybe 10g has it.

http://www.oracle.com/technology/tech/migration/ama/exchange/docs/ss2k/SELECTStatement.htm


Re: top predicate

От
"Karen Hill"
Дата:
Jan de Visser wrote:
> On Thursday 11 May 2006 16:34, Karen Hill wrote:
> > It seems PostgreSQL doesn't have a TOP Predicate.  Why is that?  Here
> > is an example:
> >
> > SELECT TOP 10 products from sales;
>
> Just for my understanding: This would return the 10 products with the most
> matching sales rows, right?
>
> jan
>
>


No, it would return the top 10 selling products in this example.