Re: Select Rows With Only One of Two Values - Mailing list pgsql-general

From Chris Angelico
Subject Re: Select Rows With Only One of Two Values
Date
Msg-id CAPTjJmqXe_WwTmpD32iszrUQM_Jo=astANrOSBqbhapb8WcUxw@mail.gmail.com
Whole thread Raw
In response to Select Rows With Only One of Two Values  (Rich Shepard <rshepard@appl-ecosys.com>)
Responses Re: Select Rows With Only One of Two Values [RESOLVED]  (Rich Shepard <rshepard@appl-ecosys.com>)
Re: Select Rows With Only One of Two Values  (Alban Hertroys <haramrae@gmail.com>)
List pgsql-general
On Sat, Jul 21, 2012 at 1:53 AM, Rich Shepard <rshepard@appl-ecosys.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

pgsql-general by date:

Previous
From: Rich Shepard
Date:
Subject: Select Rows With Only One of Two Values
Next
From: Rich Shepard
Date:
Subject: Re: Select Rows With Only One of Two Values [RESOLVED]