Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 5CEE32E3140 for ; Thu, 10 Jan 2008 09:56:50 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 07220-03-2 for ; Thu, 10 Jan 2008 09:56:41 -0400 (AST) Received: from web31811.mail.mud.yahoo.com (web31811.mail.mud.yahoo.com [68.142.207.74]) by postgresql.org (Postfix) with SMTP id 825682E30F1 for ; Thu, 10 Jan 2008 09:56:46 -0400 (AST) Received: (qmail 7854 invoked by uid 60001); 10 Jan 2008 13:56:44 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Message-ID; b=buz7agK5T4T20OziTvPgaIYcotaDwi4ixaJ3u21W9okl+PONJl+w01pCQZ21+8NiPBa9m6q9E000Rugskfjy/FI98pj3X+NfVVFnv309Fisn3PPx0dM68lMrmLBW5rkcJCkaDJ/t5AqwD87IDCUxVnIAis1mFY2qrzNhUmg6v5E=; X-YMail-OSG: 1eZOTp4VM1nY2kFzdMfUzmuWaBs7NZapr5WoB_6ZrkEXdFVVqd7B4Dajbeo5WZ3JR1NitgFaDuLpDyj_eg5OTDrEClUV4WCAG9FVFUXr2w3QnCt8AIg- Received: from [12.180.237.138] by web31811.mail.mud.yahoo.com via HTTP; Thu, 10 Jan 2008 05:56:44 PST X-Mailer: YahooMailWebService/0.7.162 Date: Thu, 10 Jan 2008 05:56:44 -0800 (PST) From: Richard Broersma Jr Subject: Re: Support for SQL TOP clause? To: pgsql-sql@postgresql.org, Chinyi Woo In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Message-ID: <554372.7292.qm@web31811.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/67 X-Sequence-Number: 29920 --- On Wed, 1/9/08, Chinyi Woo 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.