X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A3A9B8BA2F4 for ; Wed, 16 Feb 2005 16:35:41 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 77813-10 for ; Wed, 16 Feb 2005 16:35:33 +0000 (GMT) Received: from mail.99main.com (mail.99main.com [208.28.184.11]) by svr1.postgresql.org (Postfix) with ESMTP id 6D0F88BA27F for ; Wed, 16 Feb 2005 16:35:32 +0000 (GMT) Received: from 99main.com (localhost [127.0.0.1]) by mail.99main.com (8.12.8+Sun/8.12.8) with ESMTP id j1GGZUwO024952; Wed, 16 Feb 2005 11:35:30 -0500 (EST) From: "Keith Worthington" To: "PostgreSQL SQL" Cc: "Sean Davis" , "Scott Marlowe" Reply-To: KeithW@narrowpathinc.com Subject: Re: More efficient OR Date: Wed, 16 Feb 2005 11:35:30 -0500 Message-Id: <20050216162747.M40986@narrowpathinc.com> In-Reply-To: References: <20050216155901.M41773@narrowpathinc.com> X-Mailer: Open WebMail 2.50 20050106 X-OriginatingIP: 68.235.22.242 (npkeithw) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.008 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200502/164 X-Sequence-Number: 20275 > > Hi All, > > > > In several of my SQL statements I have to use a WHERE clause > > that contains mutiple ORs. i.e. > > > > WHERE column1 = 'A' OR > > column1 = 'B' OR > > column1 = 'C' > > > > Is there a more efficient SQL statement that accomplishes the > > same limiting functionality? > > > > Kind Regards, > > Keith > > > > Scott wrote: > The in() construct is (nowadays) basically the same as > ORing multiple columns; > > where column1 in ('A','B','C') > > > Sean Davis wrote > Could 'in' or 'between' do what you want? I know that using 'in' > is equivalent to what you have below. Could 'between' be more > efficient--you could do explain analyze on various options to see > what the actual plan would be. > > Sean Thanks Scott and Sean for the post. It sounds like IN will save some typing and code space but not decrease the execution time. BETWEEN won't work for my real life query because the limiting values are quite disparate. Kind Regards, Keith