View previous topic :: View next topic
|
Author |
Message |
Ashsih
New User
Joined: 20 Dec 2007 Posts: 29 Location: India
|
|
|
|
Hi All
Could u please tell me the query which can delete duplicate row in DB2 database. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
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 |
|
|
Ashsih
New User
Joined: 20 Dec 2007 Posts: 29 Location: India
|
|
|
|
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 |
|
|
the_gautam
Active User
Joined: 05 Jun 2005 Posts: 165 Location: Bangalore
|
|
|
|
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 |
|
|
nikyojin
New User
Joined: 05 Oct 2005 Posts: 94
|
|
|
|
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 |
|
|
|