Re: query assistance

From: Richard Huxton <dev(at)archonet(dot)com>
To: Jodi Kanter <jkanter(at)virginia(dot)edu>, Postgres SQL List <pgsql-sql(at)postgresql(dot)org>
Subject: Re: query assistance
Date: 2003-11-04 15:43:35
Message-ID: 200311041543.35899.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tuesday 04 November 2003 15:16, Jodi Kanter wrote:
> Is there a straight forward way to pull out duplicates in a particular
> field given a value in another field?
> For example, I have a table that lists users and study names associated
> with those users. Each user can have one or more study names. My goal is
> to determine if any of these people have duplicate study names. There
> are duplicated study names across the system and that is ok. I just want
> to see if any users have duplicate study names among their studies.

Something like:

SELECT
created_by, study_name, count(sty_pk)
FROM
study
GROUP BY
created_by, study_name
HAVING
count(sty_pk) > 1;

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Franco Bruno Borghesi 2003-11-04 21:28:12 What's wrong with this group by clause?
Previous Message Jodi Kanter 2003-11-04 15:16:30 query assistance