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

query to delete duplicate row DB2 .


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

New User


Joined: 20 Dec 2007
Posts: 29
Location: India

PostPosted: Sun Jan 20, 2008 11:46 pm
Reply with quote

Hi All

Could u please tell me the query which can delete duplicate row in DB2 database.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Mon Jan 21, 2008 3:06 am
Reply with quote

Ashsih wrote:
Could u please tell me the query which can delete duplicate row in DB2 database.
Does it have a totally duplicte key too? I did not think that was allowed.......

A little more information would be helpful....
Back to top
View user's profile Send private message
Ashsih

New User


Joined: 20 Dec 2007
Posts: 29
Location: India

PostPosted: Mon Jan 21, 2008 10:54 am
Reply with quote

As in DB2 like in orcal no concept if row id so we can delete the duplicate row and also dont want to delet by using temp table.
For ur information no primary key is define for this table!!!

For example let teble A contain three colm X , Y and Z
the contain in X Y And Z are
X Y Z
Ashish eng 11
Ashish eng 11
Sahil hin 21
Astha mar 43

i need o/p as follows
X Y Z
Ashish eng 11
Sahil hin 21
Astha mar 43

Tahnks in advanced...
Back to top
View user's profile Send private message
the_gautam

Active User


Joined: 05 Jun 2005
Posts: 165
Location: Bangalore

PostPosted: Mon Jan 21, 2008 9:29 pm
Reply with quote

hi ashish,

i am not very sure of deleting the duplicate rows in your case. however, i can give you a query to select the duplicate rows. you may modify it to serve your requirement.

SELECT * FROM TABLE1 A WHERE 1 < (SELECT COUNT(*) FROM TABLE1 B WHERE A.X = B.X)
Back to top
View user's profile Send private message
nikyojin

New User


Joined: 05 Oct 2005
Posts: 94

PostPosted: Tue Jan 29, 2008 9:54 pm
Reply with quote

Hi Ashish,

The union clause if used in the manner below can eliminate all the duplicates in the o/p of the query.

Code:
select * from tabname as tab1 union select * from tabname as tab2


For deleting the duplicate rows the following methodology can be followed

1) Create a temporary table (in DB2 or Cobol).
2) Using the above query populate all the distinct rows in the temp table.
3) Delete all the rows in the original table.
4) Copy all the rows from the temp table to the original table.

Thanks,
Nikhil S. Thayyil
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 DELETE SPUFI DB2 1
No new posts Duplicate transid's declared using CEDA CICS 3
No new posts DSNTIAUL driven delete IBM Tools 0
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top