mysql - Insert only if new value is the highest -
player 1 has finished game , got score of 10. should save score if it's high score user. how accomplish in single query? tried this:
insert highscore("score", "player") values(10, 1) (select max(score) hs highscore player = 1) < 10;
thanks
the ugly thing mysql not support insert values condition, can cheat doing this:
insert highscore (score, player) select 10, 1 dual (select max(score) highscore player = 1) < 10
this insert no rows if score higher 10, otherwise create row values need. it's easier trigger , believe has lower cost.
Comments
Post a Comment