X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 6EEE3D1B561 for ; Tue, 4 Nov 2003 15:48:08 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 21118-08 for ; Tue, 4 Nov 2003 11:47:40 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [200.46.204.70]) by svr1.postgresql.org (Postfix) with ESMTP id E00E5D1CA66 for ; Tue, 4 Nov 2003 11:47:36 -0400 (AST) Received: from anchor-post-30.mail.demon.net (anchor-post-30.mail.demon.net [194.217.242.88]) by svr4.postgresql.org (Postfix) with ESMTP id 979E61CB4654 for ; Tue, 4 Nov 2003 15:47:20 +0000 (GMT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-30.mail.demon.net with esmtp (Exim 3.35 #1) id 1AH3LI-000Krj-0U; Tue, 04 Nov 2003 15:43:40 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 25E91170FA; Tue, 4 Nov 2003 15:43:38 +0000 (GMT) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id B277216EEB; Tue, 4 Nov 2003 15:43:37 +0000 (GMT) From: Richard Huxton To: Jodi Kanter , Postgres SQL List Subject: Re: query assistance Date: Tue, 4 Nov 2003 15:43:35 +0000 User-Agent: KMail/1.5 References: <3FA7C2CE.4000902@virginia.edu> In-Reply-To: <3FA7C2CE.4000902@virginia.edu> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200311041543.35899.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/16 X-Sequence-Number: 15831 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