473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 4618

"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 line using SQLLDR and a control file to load my...
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), in which I want to eliminate any two of these...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
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 2006/321/1 , 521496 , Joe 2006/541/4 , 521496 ,...
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 copy of such rows. How to write a query to delete...
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 just want the duplicate records to show only one...
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 into duplicate(intId,varName) values(2,'raj12')...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.