Re: Using AND in query

From: David Fetter <david(at)fetter(dot)org>
To: John R Pierce <pierce(at)hogranch(dot)com>
Cc: Thomas Kellerer <spam_eater(at)gmx(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: Using AND in query
Date: 2010-08-08 19:33:40
Message-ID: 20100808193340.GC27785@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Aug 08, 2010 at 01:55:19AM -0700, John R Pierce wrote:
> >The condition
> >
> > and table.item = 'laptop' and table.item = 'Desktop'
> >
> >says: I want all rows where the column item has the value 'Laptop'
> >and *at the same time* has the value 'Desktop'
> >Which clearly cannot be the case (a column can only have a single value)
> >
> >So you need to join all "Laptop" rows to all "Desktop" rows to get
> >what you want.
>
> why not use OR ?
>
> ... AND (table.item = 'laptop' OR table.item='Desktop') ...

OR doesn't account for duplicates. Two laptops on the same date would
cause a false positive.

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Edoardo Panfili 2010-08-08 19:49:44 Re: Help with select with max and min please
Previous Message Tom Lane 2010-08-08 19:24:12 Re: Accessing a database via AJAX scripts