.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Pankaj Mishra
alex morco
Imran Ghani

Home >> Code Snippets >> SQL Query >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Get the Random Records from a Table

Posted By:Lakhan Pal Garg       Posted Date: June 16, 2010    Points: 10    Category: SQL Query    URL: http://www.dotnetspark.com  

Query to Get the Random Records from a Table in a Database.

Supoose we want to show 5 Random News on main page of the website.
Table Name:tblNews
Columns: NewsID,Description,DatePosted

SELECT TOP 5 NewsID,Description,DatePosted FROM tblNews ORDER By NEWID()

OUTPUT: 5 News will be fetched from table at Random. each times 5 different news will be picked from the table.

Thanks & Regards
Lakhan Pal Garg


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend