1

Does anyone have a query that will select n number of random rows from a SQL Server CE 4 table?

1 Answer 1

3

Have you tried:

SELECT TOP N * FROM table ORDER BY NEWID()

NEWID causes a GUID (semi-random identifier) to be created for each row in the result set and sorting by it ought to give you N fairly random results.

1
  • I thought I'd tried NEWID() before I asked the question and it didn't work, so I presumed it wasn't available with CE. I've just tried it again though and it works perfectly, so I was obviously making a silly mistake elsewhere. Thanks for the help!
    – ipr101
    Feb 12, 2012 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.