Re: query assistance - Mailing list pgsql-sql

From Richard Huxton
Subject Re: query assistance
Date
Msg-id 200311041543.35899.dev@archonet.com
Whole thread Raw
In response to query assistance  (Jodi Kanter <jkanter@virginia.edu>)
List 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


pgsql-sql by date:

Previous
From: Paul Ganainm
Date:
Subject: Re: Using UNION inside a cursor
Next
From: "Freshman"
Date:
Subject: Please help me to slove this SQL statements