I have this sql
select concat( char(FLOOR(97+ RAND()*26))
, char(FLOOR(97+ RAND()*26))
, FLOOR(100+ RAND()*999)
, char(FLOOR(97+ RAND()*26))) AS randomcode
WHERE NOT EXISTS (
SELECT *
FROM table
WHERE code_felt = randomcode );
But I can’t get it to work. Does somebody know what I am doing wrong here?
I need to make a 6 chart code in random and it does not exists in my code. I hope I can be helped.
You have to select FROM somewhere. Your SELECT does not have a table name. Since you don’t actually select random values from a table, you should use DUAL (this is a ‘fake’ table):
This will sometimes select one record, sometimes no records. If it selects no records, you have to repeat the query, I can’t think of a way to make it always select one record.