Re: Selecting dupes from table - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Selecting dupes from table
Date
Msg-id 20030624103252.GD19206@svana.org
Whole thread Raw
In response to Selecting dupes from table  (Uros <uros@sir-mag.com>)
Responses Re: Selecting dupes from table  (Uros <uros@sir-mag.com>)
List pgsql-general
On Tue, Jun 24, 2003 at 12:16:43PM +0200, Uros wrote:
> Hello ,
>
> I have table directory with 3 columns (id,url,title)
>
> I want to list all entries with duplicate urls.
>
> I tried this:
>
> select id,url,title from directory where url IN
>   (select url from directory group by url having count(url) > 1)
> ORDER by url;
>
> but this takes 30 seconds with 25.000 entries. I have index on url.
>
> Can I use any other query to select this faster.

How about:

Duplicate urls would be given by:

select url from directory group by url having count(*) > 1;

To get all the entries with those urls, something like:

select id,url,title from directory,
(select url from directory group by url having count(*) > 1) as list
where list.url = directory.url;

I hope I got the syntax right.
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> "the West won the world not by the superiority of its ideas or values or
> religion but rather by its superiority in applying organized violence.
> Westerners often forget this fact, non-Westerners never do."
>   - Samuel P. Huntington

Attachment

pgsql-general by date:

Previous
From: Jean-Christian Imbeault
Date:
Subject: Re: Selecting dupes from table
Next
From: Justin Clift
Date:
Subject: Re: [pgsql-advocacy] interesting PHP/MySQL thread