Write a single SQL to delete duplicate records from the a
single table based on a column value. I need only Unique
records at the end of the Query.

Answer Posted / yuvaevergreen

If atleast one column is distinct, we can delete using
delete statement.
EMPLOYEE TABLE:
EMPNO EMPNAME DEPT
1 YUVA SCI
2 YUVA SCI

DELETE FROM EMPLOYEE WHERE
(EMPNO, EMPNAME,DEPT)
NOT IN
(SELECT EMPNO, EMPNAME,DEPT FROM EMPLOYEE
QUALIFY ROW_NUMBER() OVER
(PARTITION BY EMPNO
ORDER BY EMPNO,EMPNAME,DEPT ASC ) = 1 );

If all the columns are same, then create and drop would be used.

EMPNO EMPNAME DEPT
1 YUVA SCI
1 YUVA SCI

CREATE EMP_NEW AS EMP WITH NO DATA;
INSERT INTO EMP_NEW
SELECT EMPNO, EMPNAME,DEPT FROM EMPLOYEE
QUALIFY ROW_NUMBER() OVER
(PARTITION BY EMPNO, EMPNAME,DEPT
ORDER BY EMPNO,EMPNAME,DEPT ASC ) = 1;
DROP TABLE EMP;
RENAME EMP_NEW TO EMP;

Is This Answer Correct ?    9 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to identify ppi columns?

649


How to explain project Architecture and flow in teradata interviews?Can please anyone help on this? Am new to teradata.

3901


What are the functions of a Parser?

602


If Fast Load Script fails and only the error tables are made available to you, then how will you restart?

631


What is meant by a Virtual Disk?

572






What is the purpose of joins in teradata and what are the available join types?

540


What is bteq script in teradata?

629


What interface is used to connect to windows based applications?

580


What is the difference between global temporary tables and volatile temporary tables?

629


How to load specific no.of records using bteq, or fastload,or multiload

1311


Why teradata is used?

574


Explain fastload in teradata?

593


What are the various reporting tools in the market?

608


What are the different methods ot loading a dimension table? A fact table etc?

570


What are the different table types that are supported by teradata?

535