dbTalk Databases Forums  

Duplication remove

comp.databases.postgresql comp.databases.postgresql


Discuss Duplication remove in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Paolo Holzl
 
Posts: n/a

Default Duplication remove - 05-15-2008 , 08:21 AM






Example

TABLE AAA
Data1,Data2,Data3,Data4

11,1,3,4
22,2,2,4
33,2,2,4
44,2,2,4
55,3,4,5
55,3,4,5
56,3,4,5
57,1,1,1

I have to reduce duplications (use last data) on Data2,Data3,Data4
Expected result

11,1,3,4
44,2,2,4
56,3,4,5
57,1,1,1

I have some way to obtain it, but the better?
I dont'use IN or EXISTS, on large tables are very slow.

Is it possible the use extra fields and more the a single SQL table.
Is it also possible use of temporary tables.

Thank's a lot
--


Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Duplication remove - 05-16-2008 , 02:02 AM






Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
TABLE AAA
Data1,Data2,Data3,Data4

11,1,3,4
22,2,2,4
33,2,2,4
44,2,2,4
55,3,4,5
55,3,4,5
56,3,4,5
57,1,1,1

I have to reduce duplications (use last data) on Data2,Data3,Data4
Expected result

11,1,3,4
44,2,2,4
56,3,4,5
57,1,1,1

I have some way to obtain it, but the better?
I dont'use IN or EXISTS, on large tables are very slow.

Is it possible the use extra fields and more the a single SQL table.
Is it also possible use of temporary tables.
If I understood you correctly, you can easily do it with DISTINCT ON:

test=> SELECT DISTINCT ON (data2, data3, data4) * FROM aaa;
data1 | data2 | data3 | data4
-------+-------+-------+-------
57 | 1 | 1 | 1
11 | 1 | 3 | 4
33 | 2 | 2 | 4
55 | 3 | 4 | 5
(4 rows)

Yours,
Laurenz Albe


Reply With Quote
  #3  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Duplication remove - 05-16-2008 , 02:02 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
TABLE AAA
Data1,Data2,Data3,Data4

11,1,3,4
22,2,2,4
33,2,2,4
44,2,2,4
55,3,4,5
55,3,4,5
56,3,4,5
57,1,1,1

I have to reduce duplications (use last data) on Data2,Data3,Data4
Expected result

11,1,3,4
44,2,2,4
56,3,4,5
57,1,1,1

I have some way to obtain it, but the better?
I dont'use IN or EXISTS, on large tables are very slow.

Is it possible the use extra fields and more the a single SQL table.
Is it also possible use of temporary tables.
If I understood you correctly, you can easily do it with DISTINCT ON:

test=> SELECT DISTINCT ON (data2, data3, data4) * FROM aaa;
data1 | data2 | data3 | data4
-------+-------+-------+-------
57 | 1 | 1 | 1
11 | 1 | 3 | 4
33 | 2 | 2 | 4
55 | 3 | 4 | 5
(4 rows)

Yours,
Laurenz Albe


Reply With Quote
  #4  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Duplication remove - 05-16-2008 , 02:02 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
TABLE AAA
Data1,Data2,Data3,Data4

11,1,3,4
22,2,2,4
33,2,2,4
44,2,2,4
55,3,4,5
55,3,4,5
56,3,4,5
57,1,1,1

I have to reduce duplications (use last data) on Data2,Data3,Data4
Expected result

11,1,3,4
44,2,2,4
56,3,4,5
57,1,1,1

I have some way to obtain it, but the better?
I dont'use IN or EXISTS, on large tables are very slow.

Is it possible the use extra fields and more the a single SQL table.
Is it also possible use of temporary tables.
If I understood you correctly, you can easily do it with DISTINCT ON:

test=> SELECT DISTINCT ON (data2, data3, data4) * FROM aaa;
data1 | data2 | data3 | data4
-------+-------+-------+-------
57 | 1 | 1 | 1
11 | 1 | 3 | 4
33 | 2 | 2 | 4
55 | 3 | 4 | 5
(4 rows)

Yours,
Laurenz Albe


Reply With Quote
  #5  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Duplication remove - 05-16-2008 , 02:02 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
TABLE AAA
Data1,Data2,Data3,Data4

11,1,3,4
22,2,2,4
33,2,2,4
44,2,2,4
55,3,4,5
55,3,4,5
56,3,4,5
57,1,1,1

I have to reduce duplications (use last data) on Data2,Data3,Data4
Expected result

11,1,3,4
44,2,2,4
56,3,4,5
57,1,1,1

I have some way to obtain it, but the better?
I dont'use IN or EXISTS, on large tables are very slow.

Is it possible the use extra fields and more the a single SQL table.
Is it also possible use of temporary tables.
If I understood you correctly, you can easily do it with DISTINCT ON:

test=> SELECT DISTINCT ON (data2, data3, data4) * FROM aaa;
data1 | data2 | data3 | data4
-------+-------+-------+-------
57 | 1 | 1 | 1
11 | 1 | 3 | 4
33 | 2 | 2 | 4
55 | 3 | 4 | 5
(4 rows)

Yours,
Laurenz Albe


Reply With Quote
  #6  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Duplication remove - 05-16-2008 , 02:02 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
TABLE AAA
Data1,Data2,Data3,Data4

11,1,3,4
22,2,2,4
33,2,2,4
44,2,2,4
55,3,4,5
55,3,4,5
56,3,4,5
57,1,1,1

I have to reduce duplications (use last data) on Data2,Data3,Data4
Expected result

11,1,3,4
44,2,2,4
56,3,4,5
57,1,1,1

I have some way to obtain it, but the better?
I dont'use IN or EXISTS, on large tables are very slow.

Is it possible the use extra fields and more the a single SQL table.
Is it also possible use of temporary tables.
If I understood you correctly, you can easily do it with DISTINCT ON:

test=> SELECT DISTINCT ON (data2, data3, data4) * FROM aaa;
data1 | data2 | data3 | data4
-------+-------+-------+-------
57 | 1 | 1 | 1
11 | 1 | 3 | 4
33 | 2 | 2 | 4
55 | 3 | 4 | 5
(4 rows)

Yours,
Laurenz Albe


Reply With Quote
  #7  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Duplication remove - 05-16-2008 , 02:02 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
TABLE AAA
Data1,Data2,Data3,Data4

11,1,3,4
22,2,2,4
33,2,2,4
44,2,2,4
55,3,4,5
55,3,4,5
56,3,4,5
57,1,1,1

I have to reduce duplications (use last data) on Data2,Data3,Data4
Expected result

11,1,3,4
44,2,2,4
56,3,4,5
57,1,1,1

I have some way to obtain it, but the better?
I dont'use IN or EXISTS, on large tables are very slow.

Is it possible the use extra fields and more the a single SQL table.
Is it also possible use of temporary tables.
If I understood you correctly, you can easily do it with DISTINCT ON:

test=> SELECT DISTINCT ON (data2, data3, data4) * FROM aaa;
data1 | data2 | data3 | data4
-------+-------+-------+-------
57 | 1 | 1 | 1
11 | 1 | 3 | 4
33 | 2 | 2 | 4
55 | 3 | 4 | 5
(4 rows)

Yours,
Laurenz Albe


Reply With Quote
  #8  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Duplication remove - 05-16-2008 , 02:02 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
TABLE AAA
Data1,Data2,Data3,Data4

11,1,3,4
22,2,2,4
33,2,2,4
44,2,2,4
55,3,4,5
55,3,4,5
56,3,4,5
57,1,1,1

I have to reduce duplications (use last data) on Data2,Data3,Data4
Expected result

11,1,3,4
44,2,2,4
56,3,4,5
57,1,1,1

I have some way to obtain it, but the better?
I dont'use IN or EXISTS, on large tables are very slow.

Is it possible the use extra fields and more the a single SQL table.
Is it also possible use of temporary tables.
If I understood you correctly, you can easily do it with DISTINCT ON:

test=> SELECT DISTINCT ON (data2, data3, data4) * FROM aaa;
data1 | data2 | data3 | data4
-------+-------+-------+-------
57 | 1 | 1 | 1
11 | 1 | 3 | 4
33 | 2 | 2 | 4
55 | 3 | 4 | 5
(4 rows)

Yours,
Laurenz Albe


Reply With Quote
  #9  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Duplication remove - 05-16-2008 , 02:02 AM



Paolo Holzl <software (AT) toglispamtek-up (DOT) com> wrote:
Quote:
TABLE AAA
Data1,Data2,Data3,Data4

11,1,3,4
22,2,2,4
33,2,2,4
44,2,2,4
55,3,4,5
55,3,4,5
56,3,4,5
57,1,1,1

I have to reduce duplications (use last data) on Data2,Data3,Data4
Expected result

11,1,3,4
44,2,2,4
56,3,4,5
57,1,1,1

I have some way to obtain it, but the better?
I dont'use IN or EXISTS, on large tables are very slow.

Is it possible the use extra fields and more the a single SQL table.
Is it also possible use of temporary tables.
If I understood you correctly, you can easily do it with DISTINCT ON:

test=> SELECT DISTINCT ON (data2, data3, data4) * FROM aaa;
data1 | data2 | data3 | data4
-------+-------+-------+-------
57 | 1 | 1 | 1
11 | 1 | 3 | 4
33 | 2 | 2 | 4
55 | 3 | 4 | 5
(4 rows)

Yours,
Laurenz Albe


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.