IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to perform delete for a selected value in column


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
mf_arun

New User


Joined: 16 Jun 2006
Posts: 1

PostPosted: Fri Jun 16, 2006 2:15 pm
Reply with quote

I need to perform delete for a selected value in column. From the result table, again I need to have deletion only for certain no. of rows. I tried the following query:
----------------------------------------------------------------------------------
DELETE FROM (SELECT col FROM Table1
WHERE col = 'value'
ORDER BY col
FETCH FIRST 3 ROWS ONLY)
----------------------------------------------------------------------------------
in QMF

I 'm getting following error message while trying to execute the above mentioned query.

----------------------------------------------------------------------------------
QUERY MESSAGES:
SQL error at or before ( (line 3, position 13).
----------------------------------------------------------------------------------

Can u please help me on the same. Or can u suggest any other way of doing the same.
Back to top
View user's profile Send private message
prasadvrk

Active User


Joined: 31 May 2006
Posts: 200
Location: Netherlands

PostPosted: Fri Jun 16, 2006 5:26 pm
Reply with quote

mf_arun wrote:
I need to perform delete for a selected value in column. From the result table, again I need to have deletion only for certain no. of rows. I tried the following query:
----------------------------------------------------------------------------------
DELETE FROM (SELECT col FROM Table1
WHERE col = 'value'
ORDER BY col
FETCH FIRST 3 ROWS ONLY)
----------------------------------------------------------------------------------
in QMF

I 'm getting following error message while trying to execute the above mentioned query.

----------------------------------------------------------------------------------
QUERY MESSAGES:
SQL error at or before ( (line 3, position 13).
----------------------------------------------------------------------------------

Can u please help me on the same. Or can u suggest any other way of doing the same.



I think you should change your query to

DELETE FROM Table1 A WHERE PRIMARYCOL IN
(
SELECT PRIMARYCOL FROM Table1 B
WHERE 3=
(
SELECT COUNT(*) FROM Table1 B
WHERE B.PRIMARYCOL > A.PRIMARYCOL
)
) ;

You may have to tweak this query a bit to get your desired result.
Please let me know if this query meets your req or not
Back to top
View user's profile Send private message
prasadvrk

Active User


Joined: 31 May 2006
Posts: 200
Location: Netherlands

PostPosted: Fri Jun 16, 2006 5:32 pm
Reply with quote

May be you need to change your query as

DELETE FROM Table1 A WHERE PRIMARYCOL IN
(
SELECT PRIMARYCOL FROM Table1 B
WHERE 3=
(
SELECT COUNT(*) FROM Table1 B
WHERE B.COL ='value'
)
) ;

Let me know if this helps
Back to top
View user's profile Send private message
prasadvrk

Active User


Joined: 31 May 2006
Posts: 200
Location: Netherlands

PostPosted: Fri Jun 16, 2006 5:44 pm
Reply with quote

I think you need both so your query should look like
DELETE FROM Table1 A WHERE PRIMARYCOL IN
(
SELECT PRIMARYCOL FROM Table1 B
WHERE 3 >
(
SELECT COUNT(*) FROM Table1 B
WHERE B.COL ='value' AND
B.PRIMARYCOL > A.PRIMARYCOL
)
) ;
Back to top
View user's profile Send private message
prasadvrk

Active User


Joined: 31 May 2006
Posts: 200
Location: Netherlands

PostPosted: Fri Jun 16, 2006 6:24 pm
Reply with quote

Some more improvement to your query , please try this


DELETE FROM Table1 A WHERE PRIMARYCOL IN
(
SELECT PRIMARYCOL FROM Table1 B
WHERE 3 =
(
SELECT COUNT(*) FROM Table1 B
B.PRIMARYCOL > A.PRIMARYCOL
)
AND WHERE B.COL ='value'

) ;
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts DELETE SPUFI DB2 1
No new posts DSNTIAUL driven delete IBM Tools 0
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
Search our Forums:

Back to Top