how to generate a unique random number in mysql

Solutions on MaxInterview for how to generate a unique random number in mysql by the best coders in the world

showing results for - "how to generate a unique random number in mysql"
Caterina
25 Jul 2020
1#query 
2SELECT FLOOR(RAND() * 99999)
3AS random_num 
4FROM YourTableName
5WHERE "random_num" 
6NOT IN (
7  SELECT YourColumnName FROM YourTableName) LIMIT 1
8
Josefa
26 Aug 2019
1DO 
2    SELECT LEFT(UUID(), 8) INTO @var;
3    INSERT INTO col (@var);
4WHILE there_is_a_unique_constraint_violation