Search Postgresql Archives

Re: Select Rows With Only One of Two Values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jul 21, 2012 at 1:53 AM, Rich Shepard <rshepard@xxxxxxxxxxxxxxx> 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

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux