Обсуждение: DISTINCT

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

DISTINCT

От
Rudi Starcevic
Дата:
Hello,

I'd like to select from one table ( contains duplicates ) into a new table.
However the new table is exactly the same as the original ( duplicates 
included )
I think I have a problem with my DISTINCT clause - sql below.

It seems the DISTINCT is applied to the whole row not just the 'phone' 
field.
Is the a way I can select the whole row into a new table based on a DISTINCT
phone number ?

Is the a way I can select the whole row into a new table based on a DISTINCT
phone number and state ?


Else I'll need to select into a table then select again etc,etc ....to 
remove duplicates.

SELECT   DISTINCT phone,   company_name,   address,   state,   idc_desc_1,   street_number,   street_name,
street_xtra,  suburb,   postcode,   area_code,   ac_phone,   fax_area_code,   fax_phone,   fax_ac_phone,   latitude,
longitude
INTO export_temp
FROM export;

Thanks
Rudi



Re: DISTINCT

От
"Christopher Kings-Lynne"
Дата:
> SELECT
>     DISTINCT phone,
>     company_name,
>     address,
>     state,
>     idc_desc_1,
>     street_number,
>     street_name,
>     street_xtra,
>     suburb,
>     postcode,
>     area_code,
>     ac_phone,
>     fax_area_code,
>     fax_phone,
>     fax_ac_phone,
>     latitude,
>     longitude
> INTO export_temp
> FROM export;

SELECT   DISTINCT ON (phone)   phone,   company_name,   address,   state,   idc_desc_1,   street_number,   street_name,
 street_xtra,   suburb,   postcode,   area_code,   ac_phone,   fax_area_code,   fax_phone,   fax_ac_phone,   latitude,
longitude
 
INTO export_temp
FROM export;



Re: DISTINCT

От
Rudi Starcevic
Дата:
Christopher,

Thank you.
I though if I'm lucky Chris will be online and will see that one.

Kind regards
Rudi.