pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: chester c young <chestercyoung@yahoo.com>
To: me@shanewright.co.uk
Cc: pgsql-sql@postgresql.org
Subject: Re: quickest query to check a table for existance of a value in a field
Date: Mon, 25 Mar 2002 13:41:12 -0800 (PST)
Message-ID: <20020325214112.27370.qmail@web12705.mail.yahoo.com> (raw)
In-Reply-To: <200203252016.g2PKGVg16516@fullerruss.dsvr.co.uk>

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



view thread (3+ messages)  latest in thread

Message-ID: <20020325214112.27370.qmail@web12705.mail.yahoo.com>
Permalink:  ../20020325214112.27370.qmail@web12705.mail.yahoo.com/
Also on:    postgresql.org/message-id/20020325214112.27370.qmail@web12705.mail.yahoo.com

 · 

reply

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: chestercyoung@yahoo.com, me@shanewright.co.uk
  Subject: Re: quickest query to check a table for existance of a value in a field
  In-Reply-To: <20020325214112.27370.qmail@web12705.mail.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