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
 

 

query to delete duplicate row DB2 .

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: query to delete duplicate row DB2 .
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: 2150
Location: At my coffee table

PostPosted: Mon Jan 21, 2008 3:06 am    Post subject: Re: query to delete duplicate row DB2 .
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    Post subject:
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    Post subject:
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    Post subject: Reply to: query to delete duplicate row DB2 .
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    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 JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm
No new posts GETMAIN/FREEMAIN query Suja.Sai CICS 9 Tue Jan 31, 2017 12:01 pm


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