Received: from web12705.mail.yahoo.com (web12705.mail.yahoo.com [216.136.173.242]) by postgresql.org (Postfix) with SMTP id 523AA47517F for ; Mon, 25 Mar 2002 16:41:11 -0500 (EST) Message-ID: <20020325214112.27370.qmail@web12705.mail.yahoo.com> Received: from [204.134.58.2] by web12705.mail.yahoo.com via HTTP; Mon, 25 Mar 2002 13:41:12 PST Date: Mon, 25 Mar 2002 13:41:12 -0800 (PST) From: chester c young Subject: Re: quickest query to check a table for existance of a value in a field To: me@shanewright.co.uk Cc: pgsql-sql@postgresql.org In-Reply-To: <200203252016.g2PKGVg16516@fullerruss.dsvr.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Archive-Number: 200203/335 X-Sequence-Number: 7210 > I want a quick way to find out if there are any rows matching a > specified value for this indexed field. I dont care how many there > are or what their properties are, just if there are any or not. > > SELECT COUNT(c2) AS num FROM mytable WHERE c2=1234; > > Thanks > Shane Try: select 1 as yes from mytable where c2=1234 limit 1; or: select 1 as yes where exists( select 1 from mytable where c2=1234 ); would be interesting to see differences in performance on your data __________________________________________________ Do You Yahoo!? Yahoo! Movies - coverage of the 74th Academy Awards® http://movies.yahoo.com/