Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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
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    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

sivatechdrive

Active User


Joined: 17 Oct 2004
Posts: 190
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: 180

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: 180

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
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 Conditional highlighting of rows in I... packerm CLIST & REXX 2 Thu Sep 21, 2017 6:50 pm
No new posts Insert a Row_number into table useit DB2 2 Tue Sep 19, 2017 1:07 pm
No new posts column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm
No new posts how to see when the last read access ... Mike 1304 DB2 1 Tue Sep 12, 2017 7:52 pm
No new posts Convert rows and column into JSON for... Dinesh Manivannan DB2 2 Sun Sep 03, 2017 6:50 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us