top predicate

Started by Karen Hillalmost 20 years ago7 messagesgeneral
Jump to latest
#1Karen Hill
karen_hill22@yahoo.com

It seems PostgreSQL doesn't have a TOP Predicate. Why is that? Here
is an example:

SELECT TOP 10 products from sales;

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Karen Hill (#1)
Re: top predicate

"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

#3Jan de Visser
jdevisser@digitalfairway.com
In reply to: Karen Hill (#1)
Re: top predicate

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!
--------------------------------------------------------------

#4Joshua D. Drake
jd@commandprompt.com
In reply to: Karen Hill (#1)
Re: top predicate

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/

#5Ben
bench@silentmedia.com
In reply to: Karen Hill (#1)
Re: top predicate

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:

Show quoted text

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

#6Karen Hill
karen_hill22@yahoo.com
In reply to: Tom Lane (#2)
Re: top predicate

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

#7Karen Hill
karen_hill22@yahoo.com
In reply to: Jan de Visser (#3)
Re: top predicate

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.