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
 

 

Retain the 1st record ; delete the rest

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Retain the 1st record ; delete the rest
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

Site Director


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

PostPosted: Thu Aug 30, 2007 9:10 pm    Post subject:
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: 1452
Location: Chicago, IL

PostPosted: Sun Sep 16, 2007 12:11 pm    Post subject: Reply to: Retain the 1st record ; delete the rest
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    Post subject:
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: 686
Location: Earth

PostPosted: Mon Sep 17, 2007 8:45 am    Post subject:
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    Post subject:
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    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 Read two inputs and write into output... murali.andaluri DFSORT/ICETOOL 6 Wed Jul 26, 2017 7:35 pm
No new posts Need to write record of PS File in ex... Chandan1993 JCL & VSAM 1 Wed Jun 07, 2017 1:35 am
No new posts Adding big TEXT lines to each record ... bshkris SYNCSORT 4 Sat May 06, 2017 1:40 am
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm
No new posts Sort Large record length cmsmoon DFSORT/ICETOOL 14 Tue Apr 11, 2017 5:49 pm


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