sql - MYSQL : Deleting a row after UPDATE in scheduled event -
hi have event selects result larger table query is:
update character_data tu, character_data ts set tu.killsz = ts.killsz tu.playeruid = ts.playeruid , tu.numberid < ts.numberid; numberid | playeruid | alive | killsz 1 555555 0 55 2 555555 1 55
the event simply
1. update character_data tu, character_data ts set tu.killsz = ts.killsz tu.playeruid = ts.playeruid , tu.numberid < ts.numberid; 2. delete character_data alive = 0 group playeruid having count(playeruid) > 1;
this line seems not working correctly:
delete character_data alive = 0 group playeruid having count(playeruid) > 1;
the wierd thing delete rows alive = 1
not 0
.
if this:
delete character_data alive = 1 group playeruid having count(playeruid) > 1;
it delete rows alive = 0 every , delete right row. why doing reverse , how can reliable result?
this works:
delete character_data playeruid in (select t1.playeruid character_data1 t1 playeruid=t1.playeruid , killsz=t1.killsz , alive=0 group playeruid having count(*)>1) limit 1
note:
it works when there 2 duplicate records.if have 3 duplicate playerid's , want delete 2 of them should change limit 2 manually.the table character_data1 temporary table created me , cant use same table inside sub-queries when using delete function should create duplicate table task.
Comments
Post a Comment