Skip site navigation (1) Skip section navigation (2)

Re: Support for SQL TOP clause?

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: pgsql-sql(at)postgresql(dot)org, Chinyi Woo <chinyi(dot)woo(at)gmail(dot)com>
Subject: Re: Support for SQL TOP clause?
Date: 2008-01-10 13:56:44
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
--- On Wed, 1/9/08, Chinyi Woo <chinyi(dot)woo(at)gmail(dot)com> wrote:

> Does Postgresql support query like SELECT *TOP 3* * FROM
> Individual  ? If I use ORDER BY, I have to write non-sql
> code to get the first row in the result set, which I try
> to avoid.

As you have seen, PostgreSQL's implementation of LIMIT predicate can produce the same results as TOP.

This is another way to get these results using neither TOP or Limit, but the query will probably not perform as quickly.

    SELECT, ...
      FROM Individual AS I1
INNER JOIN Individual AS I2
        ON <
     WHERE --any where criteria you might have
  GROUP BY, ...
    HAVING COUNT(*) < 3

Richard Broersma Jr.

In response to

pgsql-sql by date

Next:From: Gerardo HerzigDate: 2008-01-10 16:40:11
Subject: Re: trigger for TRUNCATE?
Previous:From: Reinoud van LeeuwenDate: 2008-01-10 11:46:23
Subject: Re: Support for SQL TOP clause?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group