Re: SQL question....

From: Karl Denninger <karl(at)denninger(dot)net>
To: Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: SQL question....
Date: 2008-05-20 23:17:19
Message-ID: 48335BFF.2010209@denninger.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Gurjeet Singh wrote:
> On Tue, May 20, 2008 at 11:44 PM, Karl Denninger <karl(at)denninger(dot)net
> <mailto:karl(at)denninger(dot)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,
> --
>
A small modification got CLOSE.... I can live with that set of
results..... I think.

Thanks :)

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Gurjeet Singh 2008-05-21 02:53:19 Re: SQL question....
Previous Message Gurjeet Singh 2008-05-20 20:57:59 Re: SQL question....