Tuesday, August 7, 2012

retrieve a random record from a sql server table




SELECT TOP 1 * FROM table ORDER BY NEWID()
SELECT  * FROM table ORDER BY NEWID()

A NEWID() is generated for each row and the table is then sorted by it. The first record is returned (i.e. the record with the "lowest" GUID).

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...