Monday, August 10, 2009

Random selection of a row --NEWID() (ms sql)

//Querry for selecting a random field

SELECT top 1 * FROM dbtable where status=0 order by NEWID()

//Example :
SELECT username FROM login order by NEWID();

Try :
SELECT top 15 (ROW_NUMBER() over (order by userid)) as i,username FROM login order by NEWID();

No comments:

Post a Comment