Remove redundant rows

How to remove redundant rows without any distinct columns in the table itself ?

Questions by Anurag Shahi

Showing Answers 1 - 11 of 11 Answers

kalavani

  • Jul 25th, 2011
 

redundant means repeatedly.so we take one time others negligible.because redundant affect the answer part

  Was this answer useful?  Yes

With the usage of rowid or ranking we can achieve deleting redundant rows in the table having no key or any distinct columns.

Code
  1. CREATE TABLE dup(n1 int,val1 VARCHAR2(10));

  2.  

  3. INSERT INTO dup VALUES ( 1, 'x');

  4. INSERT INTO dup VALUES ( 1, 'y');

  5. INSERT INTO dup VALUES ( 1, 'x');

  6. INSERT INTO dup VALUES ( 1, 'y');

  7. INSERT INTO dup VALUES ( 1, 'z');

  8. INSERT INTO dup VALUES ( 1, 'y');

  9. INSERT INTO dup VALUES ( 2, 'xx');

  10. INSERT INTO dup VALUES ( 2, 'xx');

  11. INSERT INTO dup VALUES ( 2, 'zz');

  12. INSERT INTO dup VALUES ( 2, 'zz');

  13.  

  14. SELECT * FROM dup;

  15.  

  16. DELETE FROM dup d1 WHERE d1.ROWID >

  17. ANY (SELECT d2.ROWID FROM dup d2 WHERE d1.n1=d2.n1 AND d1.val1=d2.val1);

  Was this answer useful?  Yes

delete from emp where rowid not in (select min(rowid) from emp group by empno);

Here all the records having max(rowid) will be deleted and records with min(rowid) will be left behind giving unique records.

You're question is vague, but from what I understand it to mean is to remove duplicate rows wihle keeping the columns in tact. The easiest way I know is to make your query based on what makes the data unique, and make your query with that in mind. For example, in table Emp, you have employee and in table payroll you have you have their work schedule and their salary information. You want to know the employee's name, their title,their weekly hours and gross pay. But, because there's a one-to-many correlation you have to find a way to make the data only appear once. I think this is how:

SELECT DISTINCT EMP.NAME, EMP.TITLE, PAYROLL.WHOURS, PAYROLL.ANNSAL
FROM EMP.EMPNO = PAYROLL.EMPNO
ORDER BY EMP.NAME

  Was this answer useful?  Yes

smonroy

  • Sep 27th, 2011
 

Hi my Friend this is the best way to you issue

DELETE FROM table_name where camp1 in (SELECT camp1 FROM table_name GROUP BY camp1 HAVING Count(camp1)>1)

Example:

DELETE FROM ubication where serial_number in
(SELECT serial_number FROM ubication
GROUP BY serial_number HAVING Count(serial_number)>1)

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions