I have table structure like that:
users
smf, user_id, group_id, status
With every query the value of smf should increase with a current max value + random number.
Here is the query
INSERT INTO users SELECT(SELECT MAX(smf) + FLOOR(RAND() * 15 from invoices ), 0, 0, '1''
My first question is about that how to keep concurrent integrity correct (max(id) may not give me the last row i`ve inserted, since someone else may have inserted since I did).
My second question is about how to get the value of FLOOR(RAND() * 15
without running second query ?