Re: Select Rows With Only One of Two Values

From: Chris Angelico <rosuav(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Select Rows With Only One of Two Values
Date: 2012-07-20 16:15:45
Message-ID: CAPTjJmqXe_WwTmpD32iszrUQM_Jo=astANrOSBqbhapb8WcUxw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Jul 21, 2012 at 1:53 AM, Rich Shepard <rshepard(at)appl-ecosys(dot)com> wrote:
> The table has a Boolean indicator column with values of 0 or 1 for each
> row in the table and another attribute column for parameter names. I need to
> find all parameter names where the indicator value is only 0 for all rows of
> that parameter. At least some of the parameters have both rows with 0 and
> rows with 1 in the indicator attribute. I want to find all (any?) that have
> only zeros.

Try this:

SELECT DISTINCT param FROM table WHERE indicator=0
EXCEPT
SELECT DISTINCT param FROM table WHERE indicator=1

You'll get a list of rows with indicator 0, and then remove from that
list any that are also found in the second query. What's left is the
rows that have only indicator 0.

Chris Angelico

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rich Shepard 2012-07-20 16:21:04 Re: Select Rows With Only One of Two Values [RESOLVED]
Previous Message Rich Shepard 2012-07-20 15:53:52 Select Rows With Only One of Two Values