Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Write a query to to delete duplicate rows?

Answer Posted / vipul dalwala

For emample we have table called DUPtable.

DESCRIBE DUPtable;

+--------+-----------------+
| Field | Type |
+--------+-----------------+
| id | Auto Increament |
| field1 | varchar(20) |
| field2 | varchar(20) |
| field3 | varchar(20) |
+--------+-----------------+

And we want to delete duplicate rows from DUPtable (Same
combination of field1, field2 and field3) .

Solution:

Step 1: Create a Temporary table;

CREATE TEMPORARY TABLE tmpDUPtable
SELECT id FROM DUPtable GROUP BY field1, field2, field3;


Step 2: Delete query to remove Rows not in 'tmpDUPtable'
table.

DELETE from DUPtable WHERE id NOT IN (SELECT id FROM
tmpDUPtable);

Step 3 DROP tmpDUPtable

DROP TABLE tmpDUPtable;


I hope this will help.

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How would you open a directory for reading in php?

1022


Tell me how to create a text file in php?

986


What are the 5 types of variables?

1029


What is the difference between php 5 and php 7?

989


How to receive a cookie from the browser?

1141


Write a program to get lcm of two numbers using php?

969


What are examples of dependent variables?

942


Tell me which function gives us the number of affected entries by a query?

1006


Explain about looping in PHP?

1073


Is key in array php?

1013


Is it worth learning php in 2019?

980


Explain what is the difference between session and cookie?

1056


Tell me how would you declare a function that receives one parameter name hello?

994


How to remove leading and trailing spaces from user input values in php?

1024


How can you increase the maximum execution time of a script in php?

955