php - using an update in an insert for mysql -
i have insert query running select subquery. needs "fork off" copies of rows finds , inserts. part works there no garbage collection. have running on database event finds records based on criteria forks off new records... runs again fork off. ideas record finds maybe updated or way stop cycle.
insert charity (pid, itemname, newval) select cha.pid, cha.itemname, 'ref') charity cha, entry ent cha.pid = ent.id , cha.status = 'pending' , cha.type = 'char' , ent.dates < curdate() , ent.total > (select sum(price) charity cha.type = 'char')
you left join against table matching forked records , exclude forked.
insert charity (pid, itemname, newval) select cha.pid, cha.itemname, 'ref') charity cha, entry ent left outer join charity cha2 on cha2.pid=cha.pid , cha2.itemname = cha.itemname , cha2.newval='ref' cha.pid = ent.id , cha.status = 'pending' , cha.type = 'char' , ent.dates < curdate() , ent.total > (select sum(price) charity cha.type = 'char') , cha2.pid null
warning - not tested. there isn't enough information me adequately specify records might have been created.
you may need add further tests in join on clause. locates record associated new record has not yet been created - in case reford newval='ref' other 2 fields match.
Comments
Post a Comment