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
How would you open a directory for reading in php?
Tell me how to create a text file in php?
What are the 5 types of variables?
What is the difference between php 5 and php 7?
How to receive a cookie from the browser?
Write a program to get lcm of two numbers using php?
What are examples of dependent variables?
Tell me which function gives us the number of affected entries by a query?
Explain about looping in PHP?
Is key in array php?
Is it worth learning php in 2019?
Explain what is the difference between session and cookie?
Tell me how would you declare a function that receives one parameter name hello?
How to remove leading and trailing spaces from user input values in php?
How can you increase the maximum execution time of a script in php?