Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2013
    Posts
    3

    Question Unanswered: Randomly picked rows

    Hi
    I need to get report with randomly picked rows. I have used

    select top 1000
    order by RAND()

    but its not work... also doesnt work NEWID and RANDOM.
    Could you pls help me?



    Another question is randomly picked rows results when 2 queries has unioned (UNION ALL). Result from query 1 + query 2 = totally 10 000 but I need to see only randomly picked 2000.
    How should I do that ?

    Thank you for advice!

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Works for me
    Code:
    select top 5 number from master..spt_values 
    where type='P' and number<20 order by newid()
    
     number      
     ----------- 
               5 
              10 
               9 
               1 
               0 
    
    (5 rows affected)
    select top 5 number from master..spt_values 
    where type='P' and number<20 order by newid()
    
     number      
     ----------- 
               3 
              15 
               1 
              19 
              12 
    
    (5 rows affected)
    q2:
    select top 10000 id from
    (select id from tab1 union all select id from tab 2)t
    order by newid()

  3. #3
    Join Date
    Feb 2013
    Posts
    3

    Randomly pivked rows

    Many thanks. I will try this.

  4. #4
    Join Date
    Feb 2013
    Posts
    3
    many thanks! I will try.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •