Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
Deleting duplicate rows from the table

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
Author Message
kvramanareddy

New User


Joined: 24 Mar 2005
Posts: 9

PostPosted: Fri Apr 22, 2005 11:03 am    Post subject: Deleting duplicate rows from the table
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
References
sivatechdrive

Active User


Joined: 17 Oct 2004
Posts: 167
Location: hyderabad

PostPosted: Fri Apr 22, 2005 2:13 pm    Post subject: Re: Deleting duplicate rows from the table
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    Post subject:
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    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);




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    Post subject: Re: Deleting duplicate rows from the table
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: 187

PostPosted: Mon May 02, 2005 10:10 pm    Post subject: Hi,
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    Post subject:
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: 187

PostPosted: Tue May 03, 2005 9:49 pm    Post subject: Hi Girishm,
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    Post subject: Re: Deleting duplicate rows from the table
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
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1