I am trying to select random rows in Sql Server using a seed.
I a,m aware of the function newid()
, however I couldn't find a way to use a seed with this function.
I want to run a code such as:
select user_id from users;
go
The code above selects users not in a random manner, I need assistance to in changing it to select users randomly according to a seed. So that if I run the same select with the same seed, I will get the same users.
Thanks, Clint
This is from MSDN that would select number between 0 to 99 and approximately top 10 percent:
So, if you want 0 to 19 then use 20 instead of 100 for example.
I have not so elegant solution but worth the try like:
See my Fiddle Demo
I used
user_id
as the seed.And this one also:
See my demo for this one also.
Try this to get 10 random users: