Entry
Is RAND() recalculated for every row in a query?
Jan 27th, 2000 16:41
Benjamin Pflugmann, Nathan Wallace, Matthias Urlichs
RAND is calculated fresh, for every row.
http://www.mysql.com/Manual_chapter/manual_Reference.html#Mathematical_functions
This means that a query like this isn't really appropriate:
SELECT an
FROM databasename.alpha_numeric
WHERE id=ROUND( (RAND()*35) 1);
The problem is that the where id= part will be recalculated for every
row, so there will be a different random number used for comparison with
each row.
Note however, that this is only true for the 3.23.x and later versions.
In older ones, rand() behaved like a constant after the first
evaluation.