Select Rows With Only One of Two Values

From: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Select Rows With Only One of Two Values
Date: 2012-07-20 15:53:52
Message-ID: alpine.LNX.2.00.1207200844110.21688@salmo.appl-ecosys.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

What I thought would be a simple, single table select keeps eluding me.
I've looked in Rick van der Laans' book and the Joe Celko books here and
have not learned how to write the query.

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.

I have tried various flavors of this non-working syntax:

SELECT DISTINCT(param) from table WHERE indicator = 0 and indicator <> 1
order by param;

and have not found the correct way of writing this either directly or as a
correlated query. The proper syntax must not be complicated and I would
appreciate learning how to write it.

Rich

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris Angelico 2012-07-20 16:15:45 Re: Select Rows With Only One of Two Values
Previous Message Christian Ullrich 2012-07-20 13:11:48 Re: I cannot insert bengali character in UTF8