One query checks for an existing time for your existing replay (regardless of the position), while the query that gets the information for that replay also ensures a position is not null (which is impossible because all replays outside the top 25 are null).
Both queries will not check the state of a position. Your new time is compared with the existing time as well as the effective time (your best time - (minus) 25th's best time (0 if there is no 25th)).
Logical error I never picked up one. Hopefully it's fixed now.