finding firstname + lastname groups

Started by blackwater devalmost 18 years ago4 messagesgeneral
Jump to latest
#1blackwater dev
blackwaterdev@gmail.com

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?

Thanks!

#2Scott Marlowe
scott.marlowe@gmail.com
In reply to: blackwater dev (#1)
Re: finding firstname + lastname groups

On Thu, Jun 19, 2008 at 1:38 PM, blackwater dev <blackwaterdev@gmail.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

#3Sam Mason
sam@samason.me.uk
In reply to: blackwater dev (#1)
Re: finding firstname + lastname groups

On Thu, Jun 19, 2008 at 03:38:28PM -0400, blackwater dev wrote:

The problem is name is not one column but made up of firstname,
lastname...how do I do this?

I'd probably do something like:

SELECT firstname, lastname, COUNT(*)
FROM people
GROUP BY firstname, lastname
HAVING COUNT(*) > 1;

Sam

#4blackwater dev
blackwaterdev@gmail.com
In reply to: Sam Mason (#3)
Re: finding firstname + lastname groups

Great, thanks!

On Thu, Jun 19, 2008 at 5:14 PM, Sam Mason <sam@samason.me.uk> wrote:

Show quoted text

On Thu, Jun 19, 2008 at 03:38:28PM -0400, blackwater dev wrote:

The problem is name is not one column but made up of firstname,
lastname...how do I do this?

I'd probably do something like:

SELECT firstname, lastname, COUNT(*)
FROM people
GROUP BY firstname, lastname
HAVING COUNT(*) > 1;

Sam

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