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 > SQL delete function by RRN

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-19-11, 12:32
cterry cterry is offline
Registered User
 
Join Date: Oct 2011
Location: Frisco
Posts: 8
SQL delete function by RRN

Found this on the web, i'm trying to delete records out of a file based on the RRN but nothing works. Why can't i just "delete from table where RN > ?" In my table, i'm wanting to delete every record beyond 4651.

Do i have to do a fullselect, and what does the OVER function do?

DELETE FROM
(SELECT ROW_NUMBER() OVER(PARTITION BY USER_SID ORDER BY USER_SID)
FROM
BILL.TEST_USERS) AS TU(RN)
WHERE
RN=1
Reply With Quote
  #2 (permalink)  
Old 10-19-11, 13:06
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
i'm wanting to delete every record beyond 4651
Please try...
Code:
DELETE FROM
       (SELECT ROW_NUMBER() OVER(ORDER BY user_sid)
         FROM  bill.test_users) AS t(rn)
 WHERE rn > 4651
;
(Removed "PARTITION BY USER_SID".)


Quote:
what does the OVER function do?
See OLAP specifications
OLAP specifications - IBM DB2 9.7 for Linux, UNIX, and Windows
Reply With Quote
  #3 (permalink)  
Old 10-19-11, 15:48
cterry cterry is offline
Registered User
 
Join Date: Oct 2011
Location: Frisco
Posts: 8
Reply to SQL Delete function

I actually tried that and got a SQL0104 error. What is wrong with this code? And why do you have to use a subselect? Thanks
delete

from
(select from row_number() over(order by atxpan)
from
jhcterry1.atpantrn) as t(rn)
where
rn > 4651
Reply With Quote
  #4 (permalink)  
Old 10-19-11, 15:58
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Please see the full text of SQL0104 error message.
And review your code carefully.

Your code includes extra "from" between "select" and "row_number()".
Reply With Quote
  #5 (permalink)  
Old 10-19-11, 16:12
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
why do you have to use a subselect?
See the delete statement itself.
If you have any other idea, please post your idea.
Reply With Quote
  #6 (permalink)  
Old 10-19-11, 16:36
cterry cterry is offline
Registered User
 
Join Date: Oct 2011
Location: Frisco
Posts: 8
Reply to SQL Delete function

still doesn't work. Is it something to do with the version of SQL i'm running perhaps?

delete
from
(select row_number() over(order by atxpan)
from
jhcterry1.atpantrn) as t(rn)
where
rn > 4651
Reply With Quote
  #7 (permalink)  
Old 10-19-11, 23:22
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
still doesn't work. Is it something to do with the version of SQL i'm running perhaps?
No one might be able to help you with such too little and vague information.

Please supply more information. At least, following item 1) and 2) are mandatory.

1) DB2 version/release and platform OS.

2) What means "doesn't work"?
2-1) Got error message(s) at compile(prepare) time or executtion time?
If so, Give us the error message(s) with full message text and codes.
2-2) Or, were results different from your expectations?
Supply test data, your received result, and your expected result.

3) From what client software did you issued the delete statement.

4) ...
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