If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Need help to delete N rows from a table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-08-06, 00:10
han316 han316 is offline
Registered User
 
Join Date: Oct 2006
Posts: 3
Need help to delete N rows from a table

I need to delete n rows from a table. I had retrieved data using

select * from table_name fetch first 100 rows only

Now,
I need to delete the same data.
I tried,

delete from (select * from table_name fetch first 100 rows only).

It doesn't work. Any suggestions. Thanks in advance.

Note: I need to get data from a table, then run a transformation using an ETL tool (Informatica) and then delete the source data once the process is complete.
Reply With Quote
  #2 (permalink)  
Old 10-08-06, 01:40
han316 han316 is offline
Registered User
 
Join Date: Oct 2006
Posts: 3
version no. DB2 for os390 v8

DB2 for os 390 v8
Reply With Quote
  #3 (permalink)  
Old 10-08-06, 03:22
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
I am not sure whether DB2 for z/OS V8 supports this, but you can try this (it uses the EMP table in the DB2 LUW sample database):

DELETE from EMP A WHERE (A.EMPNO) in
(SELECT T.EMPNO FROM
(SELECT ROW_NUMBER() OVER (ORDER BY EMPNO) AS ROWNUM, EMPNO FROM EMP) AS T
WHERE ROWNUM < 11);


Note that the ORDER BY causes the first 10 rows to be deleted according to the sequence of the EMPNO, and not the physical sequence of the rows (which could be in random order). Obviously, you could order the rows by some other other column.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #4 (permalink)  
Old 10-08-06, 17:40
han316 han316 is offline
Registered User
 
Join Date: Oct 2006
Posts: 3
I did try that..

Thanks for the response, but did try that... i get an error... Any suggestions..Would really appreciate it..

Han
Reply With Quote
  #5 (permalink)  
Old 10-08-06, 19:35
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Check the SQL Reference to see if z/OS supports ROW_NUMBER() OVER. If not, you can create a temporary table of the keys you want deleted.

If it is supported, posted your exact SQL and the exact error message.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On