DotNet Solution

  • Home
  • Asp.net
    • Controls
    • DataControl
    • Ajax
  • Web Design
    • Html
    • Css
    • Java Script
  • Sql
    • Queries
    • Function
    • Stored Procedures
  • MVC
    • OverView
    • Create First Application
  • BootStrap
    • Collapse Function

Tuesday, 8 November 2016

Get Random Rows in SqlServer

  Unknown       12:03       Queries       No comments    

How To Get  Random  ROWS in  Table  Using Sql Server


Step 1- 
             Open Sql Server and Create Table like in Ex.

Ex.

Step 2-
              We want to  fetch Unique Randomly Rows and values in table  Then use query like

Syntax-   SELECT TOP 2 * FROM tbl_Randomvalues ORDER BY NEWID() 

Result


The key here is the NEWID function, which generates a globally unique identifier (GUID) in memory for each row.By definition, the GUID is unique and fairly random; so, when you sort by that GUID with the ORDER BY clause, you get a random ordering of the rows in the table.
So finaly we get Unique and Random rows by using this query. We use Top 2 its use to only Top 2 result in table.

SELECT TOP 2 * FROM tbl_Randomvalues ORDER BY NEWID() 



  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
Email This BlogThis! Share to X Share to Facebook
Newer Post Older Post Home

0 comments :

Post a Comment

Popular Posts

  • Auto Increment Id in Sql Server
    SQL server identity column values use in table Steps- Firstly Open-> Sql Server Create Table -> First Field Like ID Usually Autoi...
  • Alter Query
    To add a column in a table, use Alter Query the following syntax: ALTER TABLE table_name ADD column_name datatype. To delete a column ...
  • MVC OverView
    I ntroduction The Model-View-Controller (MVC) architectural pattern separates an application into three main components: the model, the v...
  • (no title)
    SQL SELECT Query The SELECT statement is used to select data from a database. Query SELECT * FROM TABLE NAME. Use this query we get All...
  • Javascript Regular Expression Email Validate
    Validate Email using Regular Expression In JavaScript- 1. Create Input type Text box and and onclick cal  checkemail function of Javascr...
  • Rank Given In Table
    Rank Given in Table in SQL Server If We Want to Give Indviual Rank And Same Rank to Same data Then Use Use Of  ROW_NUMBER() Function  ...
  • How To Timer Work in Asp.net
    Using a Timer Control Inside an UpdatePanel Control When the Timer control is included inside an UpdatePanel control, the Timer contro...
  • Get Random Rows in SqlServer
    How To Get  Random  ROWS in  Table  Using Sql Server Step 1-                Open Sql Server and Create Table like in Ex. Ex. Step...
  • Values Enter With SplitFunction in Sql Server
    Basically We Use Split Function Thorugh Commma Sepertaed string value with  Comma  Means One Then more value through split function Enter...
  • CSS 3D Transforms
    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head...

Blog Archive

  • ▼  2016 ( 36 )
    • ►  February ( 1 )
    • ►  March ( 5 )
    • ►  April ( 1 )
    • ►  June ( 10 )
    • ►  July ( 6 )
    • ▼  November ( 8 )
      • Get Random Rows in SqlServer
      • MVC OverView
      • Main Advantage Of MVC
      • MVC vs ASP.NET
      • The Evolution of MVC
      • MVC Framework Architecture
      • Auto Increment Id in Sql Server
      • Install Visual Stdio Step by Step Process
    • ►  December ( 5 )
  • ►  2017 ( 1 )
    • ►  January ( 1 )
Powered by Blogger.

Categories

  • Ajax
  • AllFunction
  • Controls
  • CreateApplication
  • css
  • Function
  • javascript
  • Js
  • over view
  • OverView
  • Queries
  • StoredProcedures

Text Widget

Sample Text

Pages

  • Home

Copyright © DotNet Solution | Powered by Blogger
Design by Vibha Acharya