Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Delete Duplicate Records in the table

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Delete Duplicate Records in the table
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
No new posts Removing Duplicates based on certain ... chandracdac DFSORT/ICETOOL 8 Fri Dec 09, 2016 4:40 am
No new posts JCL to delete component in a package sundaram.naveen Compuware & Other Tools 14 Tue Nov 29, 2016 6:21 pm
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us