View previous topic :: View next topic
|
Author |
Message |
mf_arun
New User
Joined: 16 Jun 2006 Posts: 1
|
|
|
|
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 |
|
|
prasadvrk
Active User
Joined: 31 May 2006 Posts: 200 Location: Netherlands
|
|
|
|
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 |
|
|
prasadvrk
Active User
Joined: 31 May 2006 Posts: 200 Location: Netherlands
|
|
|
|
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 |
|
|
prasadvrk
Active User
Joined: 31 May 2006 Posts: 200 Location: Netherlands
|
|
|
|
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 |
|
|
prasadvrk
Active User
Joined: 31 May 2006 Posts: 200 Location: Netherlands
|
|
|
|
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 |
|
|
|