Link to home
Start Free TrialLog in
Avatar of myyis
myyis

asked on

manipulate duplicate data

My DOCUMENT table has  duplicate entries when I group BY name, size

The result of this query is

SELECT name, COUNT( * ) , id,filename  FROM DOCUMENT GROUP BY name, size HAVING COUNT( * ) >1

name          COUNT(*)      id      filename
--------------------------------------------------------------
docu1             45               33     fname1
docu2             85               59     fname2
docu3             43               33     fname5

I  want to change the  "filename" of all recurring entries to the filename of the first  entry of the group. (That means the first record of the group will be unchanged)

Can any body help me,
Thank you so much
Avatar of Gary
Gary
Flag of Ireland image

So where for example the ID is 33 all entries should be filename1 (not filename5 etc)?
Avatar of myyis
myyis

ASKER

Like this

name      size        id       filename
---------------------------------------------
docu1      10         33      fname1
docu1      10         34      fname4    change  to  fname1
docu1      10         35      fname6    change  to  fname1
docu2      20         36      fname7
docu2      20         36      fname8    change  to  fname7

Also  I need to have the list of the old (changed) "filename" values ("fname4","fname6","fname8")

Thank you
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of myyis

ASKER

if possible using SELECT somewhere
Yes, but to do what with it?
But you cannot do a recordset select while doing an update - it's one or the other
Avatar of myyis

ASKER

I will use the list to delete the repeating documents
Avatar of myyis

ASKER

I mean delete from directory. So may be I can use a SELECT first, then the 2d query to change
Delete from what directory?
This question is in the MySQL zone.
Avatar of myyis

ASKER

Yeah I know,
if you can provide me also  the SELECT query, I can use the result set of records to will be changed.
Thank you.
You can use this which will give a comma seperated field called dupes which contains all the grouped filenames

SELECT GROUP_CONCAT(filename) AS dupes FROM table GROUP BY name

Open in new window

Avatar of myyis

ASKER

Thank you for the select but also it gives the results that are unique.
I need something like this ("fname4","fname6","fname8"). Please check above
Is ID a unique auto increment field?
Avatar of myyis

ASKER

No, the PK is (ID,ORID)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of myyis

ASKER

Great!