Skip to content

Instantly share code, notes, and snippets.

@hoodasaad
Last active April 28, 2018 11:06
Show Gist options
  • Save hoodasaad/0d1ec89b45a119e8214992fcd91d43d7 to your computer and use it in GitHub Desktop.
Save hoodasaad/0d1ec89b45a119e8214992fcd91d43d7 to your computer and use it in GitHub Desktop.
Sql to Generate Random unique number
SELECT uuid() AS 'rvkey' FROM `{$prefix}visit` WHERE 'rvkey' NOT IN (SELECT `vkey` FROM `{$prefix}visit`) LIMIT 1
SELECT SUBSTRING(MD5(RAND()) FROM 1 FOR 8) AS random_charachter
FROM `table`
WHERE "random_charachter" NOT IN (SELECT `field` FROM `table`)
LIMIT 1
SELECT FLOOR(RAND() * 9999999) AS random_num
FROM `table`
WHERE "random_num" NOT IN (SELECT `field` FROM `table`)
LIMIT 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment