Write a query to to delete duplicate rows?

Answer Posted / prakash.matte

If we have table 'temp' with columns: id(primary key),
field1, field2, field3, to remove the duplicate (field1,
field2, field3) data we can use either of the below queries

1. delete t1.* from temp t1, temp t2
where t1.id>t2.id and t1.field1=t2.field1 and
t1.field2=t2.field2 and t1.field3=t2.field3;

2. alter ignore table temp ADD UNIQUE INDEX
duprows(field1,field2,field3);

> here we can remove the duprows index by using the
following query:

alter table temp drop index duprows;

we can apply index on the columns as we don't require the
duplicate data, so we don't need to execute the query to
delete the index

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of header() function in php?

549


How to convert a character to an ascii value?

560


Tell me what are the correct and the most two common way to start and finish a php block of code?

532


What is the basic syntax of Php?

620


Do you know how can php and html interact?

537






How does csrf token work?

568


Explain me soundex() and metaphone()?

547


What is the main difference between php 4 and php 5?

535


How to merge values of two arrays into a single array?

484


What is strstr php?

527


What is dao in php?

474


How send email using php?

539


Tell me what's the difference between include and require?

552


Can we override static method?

525


Tell me what is the main difference between require() and require_once()?

546