HomeНаука и техникаRelated VideosMore From: TechBrothersIT

How to get random rows from SQL Server Table - TSQL Tutorial Part 117

31 ratings | 4944 views
SQL Server / T-SQL Tutorial Scenario: How to get random rows from SQL Server Table Scenario: You are working as SQL Server developer. You are asked to provide sample random data from dbo.Customer table. You might asked to provide random 100 rows or some percent of total data from table. What query you will use to provide required output? Solution: In previous post, we learnt how to get top n rows from table. We can either provide row count or percent of records we want to get from a table by using TOP in our select query. We can use the same Top clause but as we are asked to provide the random records, we need to sort them randomly first. We can use newid() function in order by clause to sort them randomly. Link to scripts used in SQL Server / TSQL Tutorial Video http://www.techbrothersit.com/2016/06/how-to-get-random-rows-from-sql-server.html Check out our website for Different SQL Server, MSBI tutorials and interview questions such as SQL Server Reporting Services(SSRS) Tutorial SQL Server Integration Services(SSIS) Tutorial SQL Server DBA Tutorial SQL Server / TSQL Tutorial ( Beginner to Advance) http://www.techbrothersit.com/
Html code for embedding videos on your blog
Text Comments (8)
TV Travel (2 months ago)
tks so much. great tutorial
prashant wardhan (9 months ago)
for the video in first place. Now, what if I wanted a sample row with a condition such as "2 samples from 'US', and one from 'CA'... Thanks in advance.
TechBrothersIT (9 months ago)
Hi Prashant, thanks for login to TechbrothersForum and posting your questions. I have replied there. Sorry took me little time to get there. http://techbrothersforum.com/pages/details/339/SQL-random-sampling
MOHD IRFAN (9 months ago)
Its not working oracle
MOHD IRFAN (9 months ago)
Can you tell me how can do the same in oracle 11g ?
MOHD IRFAN (9 months ago)
its seem to be useful
TechBrothersIT (9 months ago)
Hi, thanks for watching the video, please join www.techbrothersforum.com to ask any question that you may have. Tech Brothers and other professionals are online at the forum to help you out quickly. Thanks
Thank You !!

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.