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

Deleting duplicate rows from the table


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

New User


Joined: 24 Mar 2005
Posts: 9

PostPosted: Fri Apr 22, 2005 11:03 am
Reply with quote

Hi,

How to delete the duplicate rows from the table by maintaining one copy(Suppose there are 3 duplicate rows and i want to delete 2 rows from the table i need to maintain ).

Please let me know.


Thanks & Regards,
K.V.Ramana Reddy.
Back to top
View user's profile Send private message
sivatechdrive

Active User


Joined: 17 Oct 2004
Posts: 191
Location: hyderabad

PostPosted: Fri Apr 22, 2005 2:13 pm
Reply with quote

Hi Friend

Write a select Cursor query & issue a delete

Or i think this query may help

DELETE field1 FROM EMP A
group by field1
Having count(field1) > 1


Regards
siva
Back to top
View user's profile Send private message
jhaam

New User


Joined: 22 Apr 2005
Posts: 3

PostPosted: Fri Apr 22, 2005 2:25 pm
Reply with quote

Hey Shiva
what is that DELETION !!!

first thing
DELETE filed1... we can't delete by fields...

second thing...

here it will delete all the rows , but he asked to delete only two rows among three rows.
Back to top
View user's profile Send private message
jhaam

New User


Joined: 22 Apr 2005
Posts: 3

PostPosted: Fri Apr 22, 2005 2:36 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);




The above code could answer ur question... I have taken this answer from the previopus posts only...
Back to top
View user's profile Send private message
kvramanareddy

New User


Joined: 24 Mar 2005
Posts: 9

PostPosted: Mon Apr 25, 2005 12:48 pm
Reply with quote

Hi Jhaam,


Thank You very much for your good reply.

Thanks & Regards,
K.V.Ramana Reddy.
Back to top
View user's profile Send private message
vijayamadhuri

Active User


Joined: 06 Apr 2005
Posts: 180

PostPosted: Mon May 02, 2005 10:10 pm
Reply with quote

Please correct me if I am wrong but we can use the DISTINCT keyword to remove duplicates.
Back to top
View user's profile Send private message
Girishm

New User


Joined: 09 Mar 2005
Posts: 35
Location: Mysore

PostPosted: Tue May 03, 2005 7:21 pm
Reply with quote

You are absolutely wrong Madhuri, the original question was to delete the duplicates from the table itself but DISTINCT keyword will not delete the duplicates from the table, instead it just avoids displaying duplicate rows for the select query.
Hope you got the clear picture now....

___________
GM
Back to top
View user's profile Send private message
vijayamadhuri

Active User


Joined: 06 Apr 2005
Posts: 180

PostPosted: Tue May 03, 2005 9:49 pm
Reply with quote

Thanks a lot for the clarification.
Back to top
View user's profile Send private message
harikgudipati

New User


Joined: 13 May 2005
Posts: 1

PostPosted: Fri May 13, 2005 11:46 pm
Reply with quote

Hi all,

I don't think the above query given by JHAAM will work. Because above query deletes all the rows not only duplicates.

Jhaam: Can you justify how it will work
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 Load new table with Old unload - DB2 DB2 6
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Duplicate transid's declared using CEDA CICS 3
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
Search our Forums:

Back to Top