Sunday, April 17, 2011

MySQL :: How to delete dummy rows in a table

Below is the solution if you don't know how many dummy records present in the table:
CREATE TABLE tmp SELECT DISTINCT * FROM emp;
DROP TABLE emp;
ALTER TABLE tmp RENAME TO emp;
Below is the process if you know the data in the table:
Let us consider below sample table:
Table name user:
fname            lname            salary
Raj                 kumar         15000
Krishna         sumanth    21000
Krishna         sumanth    21000
Mahesh         Kalyan        12000
In the above case if we have to delete the record, "Krishna" use below query:
Delete from user where fname="Krishna" and lname="sumanth" and salary = "21000" limit 1;

No comments:

Post a Comment