this is a cut and paste from one of my other answers, I will tweak it for your category thing, but bear with it until then:
Schema:
CREATE TABLE leaderBoard
( id int AUTO_INCREMENT primary key,
userID int not null,
leaderBoardID int not null,
score int not null,
UNIQUE KEY `combo_thingie1` (userID,leaderBoardID) -- unique composite
) ENGINE=InnoDB auto_increment=150;
Tests:
insert leaderBoard (userID,leaderBoardID,score) values (113,1,0)
on duplicate key update score=greatest(0,score);
insert leaderBoard (userID,leaderBoardID,score) values (113,2,0)
on duplicate key update score=greatest(0,score);
select * from leaderBoard;
+----+--------+---------------+-------+
| id | userID | leaderBoardID | score |
+----+--------+---------------+-------+
| 1 | 113 | 1 | 0 |
| 2 | 113 | 2 | 0 |
+----+--------+---------------+-------+
insert leaderBoard (userID,leaderBoardID,score) values (113,2,555)
on duplicate key update score=greatest(555,score);
select * from leaderBoard;
+----+--------+---------------+-------+
| id | userID | leaderBoardID | score |
+----+--------+---------------+-------+
| 1 | 113 | 1 | 0 |
| 2 | 113 | 2 | 555 |
+----+--------+---------------+-------+
insert leaderBoard (userID,leaderBoardID,score) values (113,2,444)
on duplicate key update score=greatest(444,score); -- ignores lower score
select * from leaderBoard;
+----+--------+---------------+-------+
| id | userID | leaderBoardID | score |
+----+--------+---------------+-------+
| 1 | 113 | 1 | 0 |
| 2 | 113 | 2 | 555 |
+----+--------+---------------+-------+