1

would like to update all record on a field which i only want it to fill it with random either Y or N

currently using:

update table1 set field1=( RAND() FROM Y FOR N)

which is not working, any idea?

1

solved with this:

update table1 set field1 = case floor(1 + rand()*2) when 1 then 'Y' else 'N' end;
1

A shorter alternative is the inline IF:

update table1 set field1 = IF(rand()*2 > 1, 'Y', 'N');

You can try it out with this demo SELECT:

SELECT IF(rand()*2 > 1, 'Y', 'N') AS indecision_demo;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.