I have a table 'match' like
id|user1|user2|paired --+-----+-----+--------+ 1 |U_1 |null |false
I need to map the new user 'U_2' to the entry where paired = false, or create a new entry in the table if no unpaired row is found.
This db is connected to a server on which several users can try to connect, so I need to find the best possible solution that speeds it up so that it does not lock the table for a long time.
the solution that I came up with was
int matchId = select id from match where ((user1 != 'U_2') AND (paired = false)); if(matchId > 0) then update table match set user2 = 'U_2' where id = matchId; else insert new row.
Please suggest a better way.
Thanks in advance.
source share