Software Engineer, Equity Strategist, Polymath.
Random your data using Order by NEWID()
This is not a new technology but I just would like to share or refresh your memory.
ORDER BY NEWID()
is used to randomly sorting query result.
it’s good if you would like to pick randomly few selected data for example : the lucky winner, the lucky customer, etc
if you want to random all of them then the query would look like this
SELECT Id FROM tableName ORDER BY NEWID()
but imagine if you would only take one data from 500K rows you have. It would take quite some time. them don’t retrieve all of them
SELECT TOP N Id FROM tableName ORDER BY NEWID()
Leave a Reply
You must be logged in to post a comment.