Updating table, choosing between 3 random strings - how?
mysql
Solution
`RAND()` returns a number between 0 and 1; if you multiply it by the number of pictures you have and take the `FLOOR()`, you can switch on the result with `ELT`:
UPDATE users SET user_profile_image =
ELT(1 + FLOOR(RAND()*4), 'adrian.jpg', 'bendix.jpg', 'hr_skaeg.jpg', 'jeppe.jpg');
Problem
I'm making standard profile pictures for 5000 users, and right now i need to insert a referance in the 'users' table. I don't want all the users to have the same standard profile picture, so i'm trying to update the 'user_profile_image' row with one of the strings listen in the query below. ``` UPDATE users SET user_profile_image = rand('adrian.jpg', 'bendix.jpg', hr_skaeg.jpg', `'jeppe.jpg') ``` The query doesn't seem to work. Is this way too simple? Any help is much appreciated! Kind regards, Mathias