Обсуждение: how to look for duplicate rows?

Поиск
Список
Период
Сортировка

how to look for duplicate rows?

От
zach cruise
Дата:
i have to clean a table that looks like so:

create table test (sn integer, fname varchar(10), lname varchar(10));
insert into test values (1, 'adam', 'lambert');
insert into test values (2, 'john', 'mayer');
insert into test values (3, 'john', 'mayer');
insert into test values (4, 'mary', 'kay');
insert into test values (5, 'john', 'mayer');
insert into test values (6, 'susan', 'boyle');
insert into test values (7, 'susan', 'boyle');
insert into test values (8, 'mark', 'ingram');

for that, i need to run a query that returns like so:

result:
is_not_distinct
2, 3, 5
6, 7

using 8.1.

Re: how to look for duplicate rows?

От
Raymond O'Donnell
Дата:
On 29/01/2010 16:40, zach cruise wrote:
> i have to clean a table that looks like so:
>
> create table test (sn integer, fname varchar(10), lname varchar(10));
> insert into test values (1, 'adam', 'lambert');
> insert into test values (2, 'john', 'mayer');
> insert into test values (3, 'john', 'mayer');
> insert into test values (4, 'mary', 'kay');
> insert into test values (5, 'john', 'mayer');
> insert into test values (6, 'susan', 'boyle');
> insert into test values (7, 'susan', 'boyle');
> insert into test values (8, 'mark', 'ingram');
>
> for that, i need to run a query that returns like so:
>
> result:
> is_not_distinct
> 2, 3, 5
> 6, 7

How about something like:

  select fname, lname from test
  group by fname, lname
  having count(1) > 1

...which gives you the names at least.

Ray.


--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

Re: how to look for duplicate rows?

От
Jayadevan M
Дата:
select distinct a.* from test a, test b where a.fname = b.fname
and a.lname=b.lname
and a.sn <> b.sn
Regards,
Jayadevan




From:        zach cruise <zachc1980@gmail.com>
To:        pgsql-general@postgresql.org
Date:        01/29/2010 10:09 PM
Subject:        [GENERAL] how to look for duplicate rows?
Sent by:        pgsql-general-owner@postgresql.org




i have to clean a table that looks like so:

create table test (sn integer, fname varchar(10), lname varchar(10));
insert into test values (1, 'adam', 'lambert');
insert into test values (2, 'john', 'mayer');
insert into test values (3, 'john', 'mayer');
insert into test values (4, 'mary', 'kay');
insert into test values (5, 'john', 'mayer');
insert into test values (6, 'susan', 'boyle');
insert into test values (7, 'susan', 'boyle');
insert into test values (8, 'mark', 'ingram');

for that, i need to run a query that returns like so:

result:
is_not_distinct
2, 3, 5
6, 7

using 8.1.

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






DISCLAIMER:


"The information in this e-mail and any attachment is intended only for the person to whom it is addressed and may contain confidential and/or privileged material. If you have received this e-mail in error, kindly contact the sender and destroy all copies of the original communication. IBS makes no warranty, express or implied, nor guarantees the accuracy, adequacy or completeness of the information contained in this email or any attachment and is not liable for any errors, defects, omissions, viruses or for resultant loss or damage, if any, direct or indirect."