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

Retain the 1st record ; delete the rest


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

New User


Joined: 06 Oct 2006
Posts: 5
Location: manila, philippines

PostPosted: Thu Aug 30, 2007 9:13 am
Reply with quote

I have a query which selects 4 equal records, i want to keep the 1st record and delete the rest. Can anyone help me on how the query should go?
Thanks for your help..
-=wastedmaky=-
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Aug 30, 2007 9:10 pm
Reply with quote

Hello,

It would help if you clarify "4 equal records". What if more or less than 4 meet the selection criteria?

You could declare a cursor, fetch the rows that meet the selection criteria, and delete the rows fetched after the first one.

If you post some example rows, it may help us understand your requirement. You example should include rows that would be selected and rows that would not.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Sun Sep 16, 2007 12:11 pm
Reply with quote

Quote:
I have a query which selects 4 equal records

Is your query designed to select only 4 records, neither less nor more.

Quote:
i want to keep the 1st record and delete the rest.

Delete from where, from the query results or from the table icon_rolleyes.gif
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Sun Sep 16, 2007 7:12 pm
Reply with quote

If the rows are identical all the way through, a DELETE FROM Table WHERE is going to delete all 4 rows. He needs to save one off in memory, delete all of them and then put one back in.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Mon Sep 17, 2007 8:45 am
Reply with quote

Can this help-

http://www.ibmmainframes.com/viewtopic.php?t=24159
Let us know if your requirement is different.
Back to top
View user's profile Send private message
md nisar

New User


Joined: 14 Sep 2007
Posts: 2
Location: pune

PostPosted: Tue Sep 18, 2007 11:06 am
Reply with quote

please check the ROWID of that 4 records ...then delete records based on the rowid.
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 How to split large record length file... DFSORT/ICETOOL 10
No new posts DELETE SPUFI DB2 1
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts DSNTIAUL driven delete IBM Tools 0
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
Search our Forums:

Back to Top