473,396 Members | 1,809 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.

Deleting duplicates

hi...

i have the table values with duplicate records, i want to delete the duplicate records, How to delete the duplicate records? I need the query to delete the duplicate rows


Example:

id ---- name
1 ---- xxxx
2 ---- yyyy
1 ---- xxxx
3 ---- zzzz
3 ---- zzzz

i want to delete the duplicate rows from the above table. Table name is sample_table.


Thanks
S.Ashokkumar
Mar 6 '07 #1
6 1872
sang
83
hi...

i have the table values with duplicate records, i want to delete the duplicate records, How to delete the duplicate records? I need the query to delete the duplicate rows


Example:

id ---- name
1 ---- xxxx
2 ---- yyyy
1 ---- xxxx
3 ---- zzzz
3 ---- zzzz

i want to delete the duplicate rows from the above table. Table name is sample_table.


Thanks
S.Ashokkumar
Hi Ashok
The DuplicateRecords are deleted by using this Query
DELETE FROM table_name WHERE id=1 LIMIT 1; same as id3.

To avoid the duplicate records set primary key to your id field.

I think it is useful to you

Thanks
Sang
Mar 6 '07 #2
Hi Ashok
The DuplicateRecords are deleted by using this Query
DELETE FROM table_name WHERE id=1 LIMIT 1; same as id3.

To avoid the duplicate records set primary key to your id field.

I think it is useful to you

Thanks
Sang

hi...

Thanks for ur reply...
i know to delete the row based on values.... consider one very big table... that table have duplicate record.... Then how can we delete the duplicare rows without specified values.

Thanks
S.Ashokkumar.
Mar 6 '07 #3
r035198x
13,262 8TB
Changed thread title.
Mar 6 '07 #4
ronverdonk
4,258 Expert 4TB
Easiest way to do this is via a temporary table. Like the following code shows

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE temp LIKE sample_table;
  2. INSERT INTO temp SELECT sample_table.* FROM sample_table;
  3. DELETE FROM sample_table 
  4.    WHERE id NOT IN (SELECT MIN(id) FROM temp GROUP BY name);
  5. DROP TABLE temp; 
Ronald :cool:
Mar 6 '07 #5
Is any other simple method to delete the duplicate records from the table?


Thanks & Regards,
S.Ashokkumar
Mar 7 '07 #6
sang
83
Is any other simple method to delete the duplicate records from the table?


Thanks & Regards,
S.Ashokkumar
Another method to do

Expand|Select|Wrap|Line Numbers
  1. create temporary table sample_table1(id int,name varchar(20));   
  2. insert into sample_table1(id,name) select DISTINCT id,name from 
  3. sample_table;   
  4. delete from sample_table;
  5. insert into sample_table(id,name) select id,name from sample_table1;
Regards,
Sang
Mar 7 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: ScottH | last post by:
I was looking for thw SQL to delete dupes from a table, and came across this. All who saw it agreed in principle, but I can't quite figure out the logic. If we are deleting all rows whose rowid...
4
by: Jerry Barnes | last post by:
Suppose that I have a table that contains a lot of records that are identical except for an id field and a date-time-stamp field. For example Id Unit Price DTS 1 A 1.00 Date 1 2 ...
18
by: Dan | last post by:
hello, I would to know if it is possible to delete an instance in an array, The following does not allow me to do a delete. I am trying to find and delete the duplicate in an array, thanks ...
1
by: Brian Keanie | last post by:
Used the "find duplicates" wizard to identify approx 500 duplicates in a single table. How do you delete the duplicates without doing it one at a time?
2
by: Zak McGregor | last post by:
Hi all I have a table, for simplicity's sake containing one field, called unid. for example, select unid, oid from table gives me something like this: unid | oid ---------+---------
19
by: MaXX | last post by:
Hi, I hope I'm not OT. I have the following issue: I want to delete a record from my db with a php script. Let's say I'm auth'd and I want to delete the record id 440. With a simple form (get...
3
by: Maury | last post by:
Hello, I have a stored procedure that deletes duplicates in one table: ..... AS BEGIN DELETE FROM mytable WHERE Id IN( SELECT Max(id)
4
by: mcca0081 | last post by:
hi - i'm trying to delete one of the duplicate records based on the most current date. here's the code for my access 2000 db. any help would be appreciated!!! - thank you kindly Sub...
1
by: chrisclarke84 | last post by:
Hi, Is it possible to delete only 1 record when you have 2 duplicate records in a table. Normally i would do a group by query, but in some cases there are records where i want duplicates and also...
4
by: N2Deep | last post by:
I have a table named SUPPORT DATA, I have a field named Serial Number. In the Serial Number field I have many duplicates, and I only want one of each. Sample serials ABB045000MG, JBX05050016 ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.