Re: [GENERAL] Selecting duplicates

Поиск
Список
Период
Сортировка
От Herbert Liechti
Тема Re: [GENERAL] Selecting duplicates
Дата
Msg-id 37AAA0EA.76C909DF@thinx.ch
обсуждение исходный текст
Список pgsql-general
--
~Adriaan Joubert wrote:

> Gary Hoffman wrote:
> >
> > Somehow, I've managed to get duplicate entries in my soon-to-be primary
> > key field. How can I select for duplicates in a field? I know how to
> > select for blank and NULL, but duplicates escape me.
>
> Sorry, I only know complicated ways of doing this. The way I usually do
> it is to create a temporary table:
>
> create temp table tmp (id int4, cnt int4);
> insert into tmp select id, count(*) from <table> group by id;

The easier way

    select field_with_duplicates, count(*) from table
      group by field_with_duplicate having count(*) > 1;

Greatings Herbie

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Herbert Liechti                            E-Mail: Herbert.Liechti@thinx.ch
ThinX networked business services               Stahlrain 10, CH-5200 Brugg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


В списке pgsql-general по дате отправления:

Предыдущее
От: Yury Don
Дата:
Сообщение: Re: [GENERAL] Selecting duplicates
Следующее
От: "Nationale HaFaBra-site"
Дата:
Сообщение: Perl DBD?