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 Using ICETOOL, how we can seperate th... bshkris SYNCSORT 5 Tue May 09, 2017 8:33 pm
No new posts Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
No new posts unload data from table with lob columns farhad_evan DB2 0 Sat Apr 22, 2017 1:32 pm
No new posts Data replication from multiple Db2 ta... kishpra DB2 9 Mon Mar 27, 2017 9:58 pm
No new posts Join giving more records than expected Danielle.Filteau SYNCSORT 2 Thu Mar 09, 2017 3:28 am


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