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
What are the php functions?
Describe the security vulnerability of PHP?
What is scope of variable in php?
What are the difference between echo and print?
In php, objects are they passed by value or by reference?
Explain what are psrs?
How to get ip address of clients machine?
Will a comparison of an integer 12 and a string "13" work in php?
How to get length of an array in PHP?
How to remove values saved in the current session?
What is the current stable version of php? What advance thing in php7?
Explain what is memcache?
Explain how we can retrieve the data in the result set of mysql using php?
What is the use of header() function in php?
What are the rules to determine the “truth” of any value which is not already of the boolean type?