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
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()
0 comments :
Post a Comment