Thursday, August 25, 2022

How to delete duplicate rows from a table

 

How to delete duplicate rows from a table

SQL> SELECT * FROM EMP;

        ID NAME
---------- --------------------
        10 SCOTT
        10 SCOTT
        20 HELLOW WORLD
        30 SMITH
        20 HELLOW WORLD
        30 SMITH

6 rows selected.


SQL> DELETE FROM TEST

WHERE ROWID NOT IN (SELECT MIN (ROWID)

FROM TEST

GROUP BY ID,NAME);

3 rows deleted.


SQL> SELECT * FROM EMP;

        ID NAME
---------- --------------------
        10 SCOTT
        20 HELLOW WORLD
        30 SMITH


SQL> COMMIT;

Commit complete.


I hope it's helpful for you. If you have any queries, don't hesitate to contact me.

Name : Muhammad Sahal Qasim
E-mail : s.m.sahal789@gmail.com

Thank you.

0 comments:

Post a Comment

If you have any doubts, please let me know. I will help you.