Re: SQL question.... - Mailing list pgsql-sql

From Gurjeet Singh
Subject Re: SQL question....
Date
Msg-id 65937bea0805201357q50071460sa1a72074c64c7c70@mail.gmail.com
Whole thread Raw
In response to SQL question....  (Karl Denninger <karl@denninger.net>)
Responses Re: SQL question....  (Karl Denninger <karl@denninger.net>)
List pgsql-sql
On Tue, May 20, 2008 at 11:44 PM, Karl Denninger <karl@denninger.net> wrote:
.... assuming the following schema:

create table access (name text, address ip)

I want to construct a SELECT statement which will return ONLY tuples containing IP and name pairs IF there is an IP that has two or more NAMEs associated with it.

I've not figured out how to do this; I can get a list of all IPs and names ordered by IP, which I could then parse with a different program (e.g. "Select name, address from access order by address"), but the idea of course is to do it with one SELECT statement and return only rows that have multiple names listed for a given IP.


try this:

select ip, name from access where ip in ( select ip from access group by ip having count(name) > 2);

heven't execued it, so may need some coaxing. Let me know the results.

Best regards,
--
gurjeet[.singh]@EnterpriseDB.com
singh.gurjeet@{ gmail | hotmail | indiatimes | yahoo }.com

EnterpriseDB http://www.enterprisedb.com

Mail sent from my BlackLaptop device

pgsql-sql by date:

Previous
From: "Harold A. Giménez Ch."
Date:
Subject: Re: SQL question....
Next
From: Karl Denninger
Date:
Subject: Re: SQL question....