From: Richard Broersma Jr <rabroersma@yahoo.com>
To: pgsql-sql@postgresql.org, Chinyi Woo <chinyi.woo@gmail.com>
Subject: Re: Support for SQL TOP clause?
Date: Thu, 10 Jan 2008 05:56:44 -0800 (PST)
Message-ID: <554372.7292.qm@web31811.mail.mud.yahoo.com> (raw)
In-Reply-To: <f5ba57b40801091913y53833e1dh78592e5bc4a24d57@mail.gmail.com>
--- On Wed, 1/9/08, Chinyi Woo <chinyi.woo@gmail.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 I1.name, ...
FROM Individual AS I1
INNER JOIN Individual AS I2
ON I1.name < I2.name
WHERE --any where criteria you might have
GROUP BY I1.name, ...
HAVING COUNT(*) < 3
ORDER BY I1.name;
Regards,
Richard Broersma Jr.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: rabroersma@yahoo.com, chinyi.woo@gmail.com
Subject: Re: Support for SQL TOP clause?
In-Reply-To: <554372.7292.qm@web31811.mail.mud.yahoo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox