Re: finding firstname + lastname groups

From: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
To: "blackwater dev" <blackwaterdev(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: finding firstname + lastname groups
Date: 2008-06-19 20:39:28
Message-ID: dcc563d10806191339p757a4ffdp2d851d06d01561a4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jun 19, 2008 at 1:38 PM, blackwater dev <blackwaterdev(at)gmail(dot)com> wrote:
> I have to find the same firstname+ lastname combo in my db and see which
> name appears the most so I basically need to do the following:
>
> select name, count(name) from people group by name having count(name)>1
>
> The problem is name is not one column but made up of firstname,
> lastname...how do I do this?

You can concatenate them. Just use a unique separator like a : symbol
or something. You can do it with a subselect if you like, or in a
single level query.

select last||':'||first, count(last||':'||first) from people group by
last||':'||first having count(last||':'||first) > 1

OR subselect style:

select a.wholename, count(a.wholename) from
(select last||':'||first as wholename from people) as a
group by a.wholename having count(a.wholename) > 1

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Wilson 2008-06-19 20:47:42 Re: renumber table
Previous Message Charles Simard 2008-06-19 19:56:31 FW: finding firstname + lastname groups