IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Delete Duplicate Records in the table


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
revathi

New User


Joined: 07 Mar 2005
Posts: 3

PostPosted: Tue Mar 22, 2005 5:12 pm
Reply with quote

1.how to delete duplicate records in a table?
2.how can we find no of rows updated in the table quickly after updation operation?
Back to top
View user's profile Send private message
ovreddy

Active User


Joined: 06 Dec 2004
Posts: 211
Location: Keane Inc., Minneapolis USA.

PostPosted: Tue Mar 22, 2005 9:04 pm
Reply with quote

Hi Revathi,

You can delete duplicate records in 2 steps...

1. Select count (1), id, name, salary
from employee (nolock)
group by id, name,salary into :hv-id,:hv-name,:hv-salary having count(1)>1;

2. Delete from employee where id=:hv-id and name=:hv-name
and salary=:hv-salary;

Number of rows updated:

When an UPDATE statement completes execution, the value of SQLERRD(3) in the SQLCA is the number of rows updated.

Bye,
Reddy.
Back to top
View user's profile Send private message
somasundaran_k

Active User


Joined: 03 Jun 2003
Posts: 134

PostPosted: Wed Mar 23, 2005 10:49 pm
Reply with quote

Reddy,
I think we can delete the duplicate records in one parse.

Code:

DELETE                                                         
FROM TABLE A                                                     
WHERE (A.COL1,A.COL2,A.COL3)
 IN (SELECT B.COL1,B.COL2,B.COL3   
                         FROM TABLE B                       
                                  WHERE A.COL1 = B.COL1             
                                    AND A.COL2 = B.COL2             
                                    AND A.COL3 = B.COL3             
                                  GROUP BY B.COL1, B.COL2, B.COL3   
                                 HAVING COUNT(*) > 1);


hth
-Som
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts DELETE SPUFI DB2 1
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Duplicate transid's declared using CEDA CICS 3
No new posts DSNTIAUL driven delete IBM Tools 0
No new posts Compare only first records of the fil... SYNCSORT 7
Search our Forums:

Back to Top