vendredi 9 décembre 2016

MYSQL Random value between 1 and MAX in Table

I need some help with a random variable in MySQL. I want it to pick a random value between 1 and the highest value in the table surnames. The solution eludes me..

 SET id = ROUND(RAND()*((SELECT COUNT(*) FROM surnames)-1)+1);                  
 SET surnameValue = (SELECT asurname FROM surnames WHERE surname_id = id);

Thank you!




Aucun commentaire:

Enregistrer un commentaire