generate unique random number using sql query
SELECT FLOOR(RAND() * 99999) AS random_num
FROM numbers_mst
WHERE "random_num" NOT IN (SELECT my_number FROM numbers_mst)
LIMIT 1
- Selects random number between 0 - 1 using RAND().
- Amplifies that to be a number between 0 - 99999.
- Only chooses those that do not already exist in table.
- Returns only 1 result.
Comments
Post a Comment