I think you'd best start by cleaningup the logic. The section
"and (select count(*)
from tblworkingcontent wc2
where wc2.idworkingcontent and wc2.metatags=v_metatags) <
(select count(*)
from tblworkingcontent wc3
where wc3.metatags=v_metatags-v_numerorighe)"
depends on the table as a whole and not on any row selected by the
"in (select idworkingcontent
from tblworkingcontent wc1
where wc1.metatags=v_metatags . . . ."
so, as far as I can see, it just switches the whole delete on and off, so it should not be in the sub-query.
. . and I don't see why you need the IN clause . . . and there is a ; missing after the final )), isn't there?
How about:
Code:delete from tblworkingcontent where metatags=v_metatags and (select count(*) from tblworkingcontent wc2 where wc2.idworkingcontent and wc2.metatags=v_metatags) < (select count(*) from tblworkingcontent wc3 where wc3.metatags=v_metatags-v_numerorighe) ;




Reply With Quote