beforehand: appologies if this a dumb question or not best practice in coding. Still working my way through Mysql.
The idea or what I tried to achieve: getting a randomized Id with a query in a calculated field. Format something like Year-Random Alphanumeric
What I got is this:
Code: Select all
SELECT CONCAT(YEAR(CURDATE()),"-", UPPER(SUBSTR(MD5(RAND()),1,6))) AS random_num FROM data_protection_data WHERE "random_num" NOT IN ( SELECT random_id FROM TABLENAME) LIMIT 1
Code: Select all
SELECT CONCAT(YEAR(CURDATE()),"-", UPPER(SUBSTR(MD5(RAND()),1,6))) AS random_num FROM data_protection_data WHERE "random_num" NOT IN ( SELECT id FROM TABLENAME) LIMIT 1