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 for deletion of first record from a table

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
ganna_f16

New User


Joined: 07 Mar 2005
Posts: 17
Location: India

PostPosted: Wed Aug 15, 2007 3:03 pm    Post subject: Query for deletion of first record from a table
Reply with quote

Hi,
I am having a table with more duplicates(for example Empno). If I run the query like
DELETE FROM EMP-TABLE where EMP-NO='007';

This is going to delete all the rows which satisfies the condition.
But my requirement is to delete only the first record i.e if the condition satisfies for three records the it should delete only first record and remaining two records should be in table.
Thanks in advance.

Regards,
Ganna.
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Aug 15, 2007 3:28 pm    Post subject:
Reply with quote

use a cursor for update. but which is the first?
Back to top
View user's profile Send private message
ruodeer

New User


Joined: 06 Jul 2007
Posts: 59
Location: home

PostPosted: Sat Aug 18, 2007 6:12 am    Post subject:
Reply with quote

yep, a method is that using a cursor to save the first coming one , then deleting the remaining..... icon_arrow.gif
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: Sat Aug 18, 2007 6:51 am    Post subject:
Reply with quote

Hello,

Reading the responses to your question shows that different people have a different understanding of your requirement.

To continue with your example (3 rows containing emp-no=007), do you really want to delete the first one encountered and keep the other 2? Seems like this would result in the table still having duplicates.

Should there not be some ordering criteria (i.e. keep the oldest or keep the newest)? Deleting an arbitrary row that happens to meet the 007 criteria seems to be less than specific.

If you more clearly define your requirement, you may get better replies.
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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


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