Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Fri, 20 Aug 2004 @ 08:23:06 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: DELETE recommendations?
 
From:   Winter, Matthew

Hi,

Not sure what release of Teradaa you are on, but the following should do the trick, on V2R4.1 and onwards.

     CREATE VOLATILE TABLE DEL_KEYS
     (
         PK1 CHAR(2)
       , PK2 CHAR(2)
       , PK3 CHAR(2)
     )
     UNIQUE PRIMARY INDEX (PK1, PK2, PK3) ON COMMIT PRESERVE ROWS;

     INSERT INTO DEL_KEYS
     SELECT PK1, PK2, PK3
     FROM TAB
     WHERE (PK1, PK2) IN
     (SELECT
        PK1, PK2
      FROM TAB
      GROUP BY 1,2
      HAVING COUNT(*) > 1)
     QUALIFY CSUM(1, PK1, PK2) > 1

     DELETE FROM TAB
     WHERE (PK1, PK2, PK3) IN
     (SELECT PK1, PK2, PK3 FROM DEL_KEYS)

     DROP TABLE DEL_KEYS;

     SELECT * FROM TAB;

Hope this helps.


Regards

Matthew Winter
Certified Teradata Master
Senior Consultant - Teradata - Sydney, Australia



     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023