Search code examples
sql-server-cesql-server-ce-4

SQL Server CE 4 - how to select n random rows from a table?


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


Solution

  • 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.