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

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

547


What are the various reporting tools in the market?

626


What is a three-tier data warehouse?

639


What is difference between user and database in teradata?

624


What is the primary index in teradata?

602






What is a level of granularity of a fact table?

651


How to view every column and the columns contained in indexes in teradata?

595


how can we analyze the locks ?

1708


What are the various indexes in teradata? How to use them?

576


How is MLOAD Client System restarted after execution?

610


Highlight a few of the important components of Teradata?

594


How do you do backup and recovery in teradata?

557


Is multi insert ansi standard?

1764


How many types of joins are there in teradata?

553


Why are oltp database designs not generally a good idea for a data warehouse?

607