472,353 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

How to eliminate duplicate IDs from a table

Hello.

I've got a 'books' table with 'id', 'name', 'author' and
'isbn' fields.

Due to an error, my books are duplicated, so I've got (e.g.):
430 - Moby Dick - Herman Melville - 0192833855
430 - Moby Dick - Herman Melville - 0192833855
528 - A Tale of Two Cities - Charles Dickens - 0141439602
528 - A Tale of Two Cities - Charles Dickens - 0141439602

And when trying to find a book by its name, I get two
entries instead of one.

I would like:
1) To set id as "unique id"
2) To temove the duplicates IDs from the table

Any suggestion? Best regards and thank you very much.
Jul 19 '05 #1
2 4563

"Francesco Moi" <fr**********@europe.com> wrote in message
news:5b**************************@posting.google.c om...
Hello.

I've got a 'books' table with 'id', 'name', 'author' and
'isbn' fields.

Due to an error, my books are duplicated, so I've got (e.g.):
430 - Moby Dick - Herman Melville - 0192833855
430 - Moby Dick - Herman Melville - 0192833855
528 - A Tale of Two Cities - Charles Dickens - 0141439602
528 - A Tale of Two Cities - Charles Dickens - 0141439602

And when trying to find a book by its name, I get two
entries instead of one.

I would like:
1) To set id as "unique id"
2) To temove the duplicates IDs from the table

Any suggestion? Best regards and thank you very much.


I'm reasonably new to MySQL (six months) but here is my twopence worth...

One solution (which wouldn't remove the duplicate keys) is to perform your
select query as you are now, but put a "GROUP BY ISBN" at the end of your
query statement... This should remove duplicate records being returned... I
think...

but if I had to do what you needed to do (and I stress *I* as this solution
may not be attractive in a large database environment) , I would make a copy
of the table - same structure, but have ID and ISBN in the new table set as
unique... I can program in PHP so I'd have it read your original table and
insert one record at a time in to your new table - duplicate INSERTs would
automatically then be ignored in the new table - I'd then replace the old
table with the new one... its not sexy, but it would work... however a large
database and/or a busy system could make this solution very very time
consuming.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?
Jul 19 '05 #2

"Francesco Moi" <fr**********@europe.com> wrote in message
news:5b**************************@posting.google.c om...
Hello.

I've got a 'books' table with 'id', 'name', 'author' and
'isbn' fields.

Due to an error, my books are duplicated, so I've got (e.g.):
430 - Moby Dick - Herman Melville - 0192833855
430 - Moby Dick - Herman Melville - 0192833855
528 - A Tale of Two Cities - Charles Dickens - 0141439602
528 - A Tale of Two Cities - Charles Dickens - 0141439602

And when trying to find a book by its name, I get two
entries instead of one.

I would like:
1) To set id as "unique id"
2) To temove the duplicates IDs from the table

Any suggestion? Best regards and thank you very much.


I'm reasonably new to MySQL (six months) but here is my twopence worth...

One solution (which wouldn't remove the duplicate keys) is to perform your
select query as you are now, but put a "GROUP BY ISBN" at the end of your
query statement... This should remove duplicate records being returned... I
think...

but if I had to do what you needed to do (and I stress *I* as this solution
may not be attractive in a large database environment) , I would make a copy
of the table - same structure, but have ID and ISBN in the new table set as
unique... I can program in PHP so I'd have it read your original table and
insert one record at a time in to your new table - duplicate INSERTs would
automatically then be ignored in the new table - I'd then replace the old
table with the new one... its not sexy, but it would work... however a large
database and/or a busy system could make this solution very very time
consuming.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: gilgantic | last post by:
Is there anyway of eliminating duplicate entries as the database loads data using SQLLDR and/or .ctl (Control File)? I use the following command...
1
by: Julio Allegue | last post by:
I am working with SQL 8.00. I have the following tables TABLE ClientInfo CheckNum Account Name Addr1 City State Zip...
3
by: Tony Young | last post by:
Hi, I have a multimap container. I want to eliminate all "duplicate" elements. By duplicate I mean something like (3, 4), (4, 3) and (4, 3),...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ...
4
by: sandi | last post by:
hi there i have fields name called .. PAF (text) , PNo (Number ) , LastName (Text) 2006/214/2 , 220101 , Winne 2006/321/3, 521496 , Joe...
10
by: ranjitkumar | last post by:
Hi, Do anyone know a query for the following senario, I have a table in which i have multiple rows with the same entry. I want to keep only one...
4
by: elainenguyen | last post by:
I am trying to generate a query from a table which has multiple dublicate records, but in the query, I don't want to show the duplicate record. I...
1
by: bhaskar321 | last post by:
Hi all, i am new to access could any one tell me how can i eliminate duplicate records from the query Thanks, Bhaskar
3
by: rajeshkrsingh | last post by:
Hi friends, Step1- create table duplicate ( intId int, varName varchar(50) ) insert into duplicate(intId,varName) values(1,'rajesh') insert...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.