Showing posts with label RAND(). Show all posts
Showing posts with label RAND(). Show all posts

Wednesday, 9 March 2011

Return a random row - SQL

Instead of using the RAND() function which I believe is not truly random since using the same seed value results in the same output:



Whereas, CHECKSUM(NEWID()) would work:


and can thus be used to return a random row:


SELECT TOP(1) School.SchoolNameFROM School
ORDER BY CHECKSUM(NEWID());