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
 

 

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 Loading data to table gives wrong for... Raghu navaikulam DB2 16 Thu Jul 13, 2017 2:11 pm
No new posts compare 2 rows within the same file ram_vizag SYNCSORT 7 Wed Jun 14, 2017 12:34 am
No new posts Using ICETOOL, how we can seperate th... bshkris SYNCSORT 5 Tue May 09, 2017 8:33 pm
No new posts unload data from table with lob columns farhad_evan DB2 1 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


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