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
LVL 1
myyisAsked:
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.

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

Open in new window


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

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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

myyisAuthor Commented:
if possible using SELECT somewhere
0
GaryCommented:
Yes, but to do what with it?
But you cannot do a recordset select while doing an update - it's one or the other
0
myyisAuthor Commented:
I will use the list to delete the repeating documents
0
myyisAuthor Commented:
I mean delete from directory. So may be I can use a SELECT first, then the 2d query to change
0
GaryCommented:
Delete from what directory?
This question is in the MySQL zone.
0
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.
0
GaryCommented:
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

0
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
0
GaryCommented:
Is ID a unique auto increment field?
0
myyisAuthor Commented:
No, the PK is (ID,ORID)
0
GaryCommented:
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

0
myyisAuthor Commented:
Great!
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.