Subject Re: How to delete the output of this "select first 100 seqno from repl_log where relationno =11 order by seqno"
Author Svein Erling Tysvær
--- In firebird-support@yahoogroups.com, "Mohd. Jeffry" wrote:
> Dear All,
>
> How to delete the output of this "select first 100 seqno from
> repl_log where relationno =11 order by seqno"
>
> Doind this:-
>
> "delete from repl_log where exists (select first 100 seqno from
> repl_log where relationno =11 order by seqno) "
>
> seems like deleting the who table instead of 100 records that I
> wanted to delete. Anybody know why?

Because the subselect is executed once for every row, and when you
execute it for the 50th time records 50 through 149 will be the first
100.

> * repl_log is a table. relationno and seqno are fields in repl_log
> table.
> ** I want to delete the first 100 data with relationno = 11 sorted
> by seqno

I think a stored procedure is the way to go. Alternatively, you could
use two statements and an additional table and do

INSERT INTO <newtable>
SELECT FIRST 100 <pk> FROM repl_log

DELETE FROM repl_log
WHERE repl_log.<pk> = (SELECT <newtable>.<pk> FROM <newtable>)

HTH,
Set