If i have more than one simillar entries in my table and i want to delete all but one particular entry, what is the way
deleting simillar rows
Collapse
X
-
This cannot be done in a single SQL query, you need to use some other alternatives.
1. You can create a stored procedure or a function.
2. You can use temporary tables and perform delete operation. (Select distinct rows and put it in temporary table, delete from base table and insert the data back in main table.) -- Not efficient way.
3. Use LOOP to delete individual records. This can be automated in a function.
Let me know how did you achieved this.
Regards
-- SanjayComment
-
You can try this stored procedure:
RegardsCode:DROP PROCEDURE remove_duplicate @ CREATE PROCEDURE remove_duplicate() LANGUAGE SQL BEGIN CREATE TABLE t1 LIKE a; INSERt INTO t1 SELECT DISTINCT(a) FROM a; DELETE FROM a; INSERT INTO a SELECT * FROM t1; END @
-- SanjayComment
Comment