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
MySQL Server

Avatar of undefined
Last Comment
myyis

8/22/2022 - Mon
Gary

So where for example the ID is 33 all entries should be filename1 (not filename5 etc)?
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
Gary

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
myyis

ASKER
if possible using SELECT somewhere
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Gary

Yes, but to do what with it?
But you cannot do a recordset select while doing an update - it's one or the other
myyis

ASKER
I will use the list to delete the repeating documents
myyis

ASKER
I mean delete from directory. So may be I can use a SELECT first, then the 2d query to change
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Gary

Delete from what directory?
This question is in the MySQL zone.
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.
Gary

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

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
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
Gary

Is ID a unique auto increment field?
myyis

ASKER
No, the PK is (ID,ORID)
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Gary

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
myyis

ASKER
Great!