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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

So where for example the ID is 33 all entries should be filename1 (not filename5 etc)?
myyisAuthor Commented:
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
UPDATE table1 a
(SELECT filename,name FROM table1) b
ON =
SET a.filename=b.filename

Open in new window

list of the old (changed) "filename"
a list where?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

myyisAuthor Commented:
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
myyisAuthor Commented:
I will use the list to delete the repeating documents
myyisAuthor Commented:
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.
myyisAuthor Commented:
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

myyisAuthor Commented:
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?
myyisAuthor Commented:
No, the PK is (ID,ORID)
SELECT filename
FROM table1 a
WHERE filename NOT IN 
(SELECT filename FROM (select name,filename from table1 group by name) b) 

Open in new window

myyisAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.