Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to delete first N rows in DB2 ?

Posted on 2004-10-11
5
Medium Priority
?
2,525 Views
Last Modified: 2012-06-21
Hi, I am trying to delete first N rows in a DB2 command,
however I can't/don't want to use:
"DELETE FROM TABLE_NAME WHERE COL_NAME IN (SELECT COL_NAME FROM TABLE_NAME FETCH FIRST 'N' ROWS ONLY)"

I have a dynamic build of the delete statement and I have what I have is a constant delete statement that I can add things before it, in the middle of it or after it but I really don't want to change the base delete.

Thanks,
   AmS.
0
Comment
Question by:ams61
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12277816
You didn't explain why you don't want to use a query with a sub-select, so I'm not sure what you're looking for, but one option is to create a bit field with a default of zero, set it to 1 when you want it deleted, then run a DELETE statement with a WHERE clause that limits the deletion to records where the value is 1.
0
 

Author Comment

by:ams61
ID: 12282155
Thanks,
I will explain... I have a constant delete sql statement that I can add parts to its beginning, and\or to its end, I can also add constant statements into the delete statement but it will be very dificult to me to change the original delete statement, especially if I don't know from which table I am going to delete (the delete statement is built dynamicly).
0
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 1000 total points
ID: 12286867
Is
>I have a constant delete sql statement that I can add parts to
just another way of saying that you build the statement dynamically?

If so, I don't see why you couldn't add
   WHERE COL_NAME IN (SELECT COL_NAME FROM TABLE_NAME FETCH FIRST 'N' ROWS ONLY)
as needed.

Also, if you're building the delete statement dynamically, I don't understand what you mean about not being able to "change the original delete statement".
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question